<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

<link rel="shortcut icon" href="gfx/favicon.ico" />
<title>Friendly Gaming Simplifier</title>

<link type="text/css" href="css/redmond/jquery-ui-1.8.10.custom.css" rel="stylesheet" />
<link type="text/css" href="css/share.css" rel="stylesheet" />
<link type="text/css" href="css/demo_page.css" rel="stylesheet" />
<link type="text/css" href="css/demo_table.css" rel="stylesheet" />
<link type="text/css" href="css/demo_table_jui.css" rel="stylesheet" />
<link type="text/css" href="css/jquery.contextMenu.css?version=1.1.0.30" rel="stylesheet" />
<link type="text/css" href="css/jquery.tooltip.css?version=1.1.0.30" rel="stylesheet" />

<script type="text/javascript" src="scripts/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="scripts/jquery-ui.min.js"></script>
<script type="text/javascript" src="scripts/jquery.tooltip.min.js"></script>


<script type="text/javascript" src="scripts/jquery.utils.js"></script>
<script type="text/javascript" src="scripts/jquery.contextMenu.js?version=1.1.0.30"></script>
<script type="text/javascript" src="scripts/jquery.dataTables.min.js"></script>

<script type="text/javascript" src="scripts/time.js?version=1.1.0.30"></script>
<script type="text/javascript" src="scripts/notices.js?version=1.1.0.30"></script>
<script type="text/javascript" src="browser_files/browser.js?version=1.1.0.30"></script>


<script type="text/javascript">

$.fn.dataTableExt.afnSortData['dom-text'] = function  ( oSettings, iColumn )
{
	var aData = [];
	$( 'td:eq('+iColumn+') span', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
		aData.push( $(this).text() );
	} );
	return aData;
}

jQuery.expr[':'].Contains = function(a,i,m){
     return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};

var loaded = 0;
var isScreenLocked = false;
var chatInterval = null;

var screenLockedData = []


function updateLoaded()
{
	loaded++;
	$( "#progressbar" ).progressbar('option', 'value', loaded*20);
	
	if(loaded == 5)
	{
		updateCount();
		$( "#dialog-loading" ).dialog("close");
		setInterval(function(){ updateTimeAgo($('.gameContent:visible').children('div:visible').attr('id')); }, 20000);
		checkIconsCountInGameSelector();
	}
}

function addDataToScreenLocked(callback, id, data)
{
	var el =
	{
		callback:	callback,
		id: 		id,
		data:		data
	}
	screenLockedData.push(el);
}

	
	function hiddenFeed(gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var el1		= $('div#'+game+'BonusesPendingList');
		var el2 	= $('div#'+game+'ManualBonusesList');
		
		var text = '<strong>There was a problem collecting bonuses. You may have this game hidden in your news feeds.<br /><br />To unhide it, follow this steps: <br /><br />Go to the Facebook homepage. Select news feed. Scroll down until you reach the bottom of the page. There (just above the copyright Facebook information) is an option bar (if you haven\'t reached the bottom yet it displays a timer of 3 flashing bars). This bar has 2 options -1- older post (to read further back) and -2- edit options. Select -2- and you will get a popup screen where you can select what you want to see in your news feeds and what persons/applications are hidden from your newsfeed, you can deselect the application there (Thanks to Raymond for the guide).</strong><br /><br /><br /><br />';
		
		if(el1.length > 0)
		{
			el1.prev().height(300).find('.submenuInfo').html(text);
		}
		else if(el2.length > 0)
		{
			el2.prev().height(300).find('.submenuInfo').html(text);			
		}
	}
	
	function SelectFavourites(gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';
		
		ClearSelection(gameID);
		$('.favouritesTable', 'div#'+game+opt).find('input[name="neighArr[]"]:lt(25)').each(function() { $(this).click(); });
	}
	
	function ClearSelection(gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';
		$('input[name="neighArr[]"]', 'div#'+game+opt).removeAttr('checked');
	}
	
	function SelectNonFavourites(gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';
		
		ClearSelection(gameID);
		$('.neighborsTable', 'div#'+game+opt).find('input[name="neighArr[]"]:lt(25)').each(function() { $(this).click(); });
	}
	
	function listGifts(gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';
		
		var el = $('.sendToGiftsList','div#'+game+opt);
		
		el.append('<h3 style="text-align: center">'+bkP.getMsg('MessageToAddToYourGift')+': <input type="text" name="messageToAdd" class="messageToAddToGift" /></h3><br /><br class="clear" style="clear:both"/>');
		
		for(var id in bkP.giftsArray[gameID])
		{
			var v = bkP.giftsArray[gameID][id];
			el.append('<div class="selectGiftToSend" gameID="'+gameID+'" title="'+v.name+'" alt="'+v.name+'" giftID="'+id+'"><img  style="width: 32px; height: 32px;margin:2px auto;" src="http://fgs.rzadki.eu/reqs/'+game+'/'+id+'.png"><div style="font-size: 11px;">'+v.name+'</div></div>');
		}
		
		
		if(bkP.options.games[gameID].defaultGift == 0)
		{
			el.children('div:first').addClass('selected');
		}
		else
		{
			el.children('div[giftID="'+bkP.options.games[gameID].defaultGift+'"]').addClass('selected');
		}
		el.append('<br class="clear" style="clear:both"/>');
	}
	
	function SendGifts(gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';

		var sendTo = [];
		
		$('input[name="neighArr[]"]:checked:visible','div#'+game+opt).each(function()
		{
			sendTo.push($(this).val());
		});
		
		if(sendTo.length == 0)
		{
			alert(bkP.getMsg('YouMustSelectAtLeastOnePerson'));
			return;
		}
		
		var messageToAddToGift = $('.sendToGiftsList > h3 > input.messageToAddToGift','div#'+game+opt).val();

		var gift 	 = $('.sendToGiftsList > div.selected','div#'+game+opt).attr('giftID');
		var giftName = $('.sendToGiftsList > div.selected','div#'+game+opt).attr('title');
		
		var params = {
			gift: gift,
			gameID:	gameID,
			sendTo: sendTo,
			messageToAdd: messageToAddToGift
		};
		
		$('div#'+game+opt, '#'+game+'Game').children().addClass('hide');
		$('div#'+game+'SendFreeGifts > .submenu', '#'+game+'Game').children('button:gt(0)').addClass('hide');
		
		$('div#'+game+opt, '#'+game+'Game').prepend('<div class="sendingGiftProgress"><h3 class="center"><img src="gfx/loading.gif"><br />'+bkP.getMsg('SendingGiftToNumberOfPeople', [giftName, sendTo.length])+'</h3></div>');
				
		bkP[game].Freegifts.Click(params);
		
		//bkP.frontierville.Freegifts.Click({gift:'care_package', gameID: '201278444497', sendTo: ['100001178615702']});
	}
	
	function freegiftSuccess(data, data2)
	{
		var gameID = data.gameID;
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';
		
		$('div#'+game+opt, '#'+game+'Game').children('.sendingGiftProgress').html('<h3 class="center"><img src="gfx/90px-check.png"><br /><img src="gfx/loading.gif"><br /> '+bkP.getMsg('Success')+'<br />'+bkP.getMsg('WaitingForUpdatedNeighborsList')+'</h3>');
		
		$(getGiftHistoryRow(gameID, data, data2)).prependTo('#'+game+'SendFreeGiftsHistoryList');
	}
	
	function freegiftError(gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';	
		
		$('div#'+game+'SendFreeGifts > .submenu', '#'+game+'Game').children('button:gt(0)').removeClass('hide');
		$('div#'+game+opt, '#'+game+'Game').children().removeClass('hide');
		
		$('div#'+game+opt, '#'+game+'Game').children('.sendingGiftProgress').html('<h3 class="center"><img src="gfx/90px-cancel.png"><br /> There was an error with sending gifts. It could one of this:<br />- you reached facebook limit for sending gifts for this application,<br />- there was a connection error,<br />- you choose gift that requires level that you don\'t have. Try again.</h3>');
		
	}
	

	function getGiftHistoryRow(gameID, v, thankYou)
	{
		var game = bkP.gamesData[gameID].systemName;
		
		if(thankYou != '' && thankYou != 0)
		{
			var thankText = '<br /><br />'+bkP.getMsg('ThankYouGift');
		}
		else
		{
			var thankText = '';
		}		
		return  '<div class="freegiftHistory updateTimeAgo" title="'+v.friend+'" alt="'+v.friend+'" time="'+v.time+'"><span class="timeAgo">'+format_time_ago(v.time)+'</span><br /><img  style="width: 32px; height: 32px;margin:2px auto;" src="http://fgs.rzadki.eu/reqs/'+game+'/'+v.gift+'.png"><div style="font-size: 11px;">'+v.friend+thankText+'</div></div>'
	}
	
	function checkIfBonusIsManual(gameID, typeText)
	{
		var ret = false;
		$(bkP.gamesData[gameID].filter.bonusesNewWindow).each(function(k,v)
		{
			var re = new RegExp(v, "i") ;
			
			if(re.test(typeText))
			{
				ret = true;
				return false;
			}
		});
		
				
		return ret;
	}
	
	function checkIfRequestIsManual(gameID, typeText)
	{
		var ret = false;
		$(bkP.gamesData[gameID].filter.requestsNewWindow).each(function(k,v)
		{
			var re = new RegExp(v, "i") ;
			
			if(re.test(typeText))
			{
				ret = true;
				return false;
			}
		});
		
		return ret;
	}
	
	function getNewBonusRow(gameID, v)
	{
		var title = v.title;
		title = title.replace(/'/gi, '');

		var newUrl = v.url;
		
		return '<div onmousedown="onMouseDownTest(event)" id="'+v.id+'" gameID="'+gameID+'" search-title= "'+title+'" title="'+v.text+'" time="'+v.time+'" url="'+newUrl+'" class="bonusItem showContext updateTimeAgo processBonusClick"><span class="timeAgo">'+format_time_ago(v.time)+'</span><span class="bonusError"></span><img NOsrc="'+v.image+'"><span class="title">'+v.title+'</span><span class="description hide">'+v.text+'</span><span class="deleteIcon" title="Click to delete"></span></div>';
	}
	
	function getNewRequestRow(gameID, v)
	{
		var game = bkP.gamesData[gameID].systemName;
		var title = v.title;
		title = title.replace(/'/gi, '');
		
		if(v.image.indexOf('http') != -1)
		{
			var url = v.image;
		}
		else
		{
			var url = 'http://fgs.rzadki.eu/reqs/'+game+'/'+v.image+'.png';
		}
		
		return '<div id="'+v.id+'" gameID="'+gameID+'" search-title="'+title+'" origTitle="'+v.title+'" time="'+v.time+'" postdata="'+v.post+'" class="requestItem showContextRequests updateTimeAgo processRequestClick"><span class="timeAgo">'+format_time_ago(v.time)+'</span><span class="bonusError"></span><img NOsrc="'+url+'" onError="processImageError(this)"><span class="title">'+v.title+'</span><span class="description hide">'+v.text+'</span></div>';
	}
	
	function getNewManualBonusRow(gameID, v)
	{
		var title = v.title;
		title = title.replace(/'/gi, '');
		
		return '<div id="'+v.id+'" gameID="'+gameID+'" search-title="'+title+'" title="'+title+'" time="'+v.time+'" url="'+v.url+'" class="manualItem showContextManual updateTimeAgo manualBonus processManualBonusClick"><span class="timeAgo">'+format_time_ago(v.time)+'</span><span class="bonusError"></span><img NOsrc="'+v.image+'"><span class="title">'+v.title+'</span><span class="description hide">'+v.text+'</span><span class="deleteIcon" title="Click to delete"></span></div>';
	}
	
	function getNewManualRequestRow(gameID, v)
	{
		var game = bkP.gamesData[gameID].systemName;
		var title = v.title;
		title = title.replace(/'/gi, '');
		
		if(v.image.indexOf('http') != -1)
		{
			var url = v.image;
		}
		else
		{
			var url = 'http://fgs.rzadki.eu/reqs/'+game+'/'+v.image+'.png';
		}
		
		return '<div id="'+v.id+'" gameID="'+gameID+'" search-title="'+title+'" title="'+title+'" origTitle="'+v.title+'" time="'+v.time+'" postdata="'+v.post+'" class="manualItem updateTimeAgo manualRequest processManualRequestClick"><span class="timeAgo">'+format_time_ago(v.time)+'</span><span class="bonusError"></span><img src="'+url+'" onError="processImageError(this)"><span class="title">'+v.title+'</span><span class="description hide">'+v.text+'</span></div>';
	}
	
	function processImageError(e)
	{
		var el = $(e);
		el.attr('src', 'icons/reqs/noimage.png');
	}
	
	function processManualBonusClick(el)
	{
		var gameID = el.attr('gameID');
		el.unbind('click');
		var URI = el.attr('url');
		el.remove();
		bkP.database.deleteItem('bonuses', gameID, el.attr('id'), 0);
		bkP.database.deleteItem('bonuses', gameID, el.attr('id'), 1);
		bkP.openURI(URI, true);
		updateCount(gameID);
	}
	
	function processManualRequestClick(el)
	{
		var gameID = el.attr('gameID');
		bkP.database.deleteItem('requests', gameID, el.attr('id'), 0);
		bkP.database.deleteItem('requests', gameID, el.attr('id'), 1);
		bkP.prepareLinkForGame('', el.attr('id'), el.attr('postData'), true);
		el.remove();
		updateCount(gameID);
	}
	
	function addNewBonus(data2)
	{
		var gameID = data2[0][1];
		var game = bkP.gamesData[gameID].systemName;
		
		if(isScreenLocked)
		{
			addDataToScreenLocked('addNewBonus', '', data2);
			return;
		}
		
		
		$('div#'+game+'BonusesPendingList', '#'+game+'Game').prev().height(85).find('.submenuInfo').html('');
		$('div#'+game+'ManualBonusesList', '#'+game+'Game').prev().height(85).find('.submenuInfo').html('');
		
		var html = '';
		var htmlManual = '';
			
		var ids = [];
		
		$(data2).each(function(ind,data)
		{
			var itID = parseInt(data[0]);
			
			if($.inArray(itID, ids) != -1 || $('#'+itID).length > 0)
				return;
			ids.push(itID);
			
			var v = {	id: data[0],	title: data[2],	text: data[3],	image: data[4],	url: data[5],	time: data[6]	}
			
			if(checkIfBonusIsManual(gameID, v.title))
			{
				htmlManual += getNewManualBonusRow(gameID, v);
			}
			else
			{		
				html += getNewBonusRow(gameID, v);
			}
		});

		$('div#'+game+'ManualBonusesList').prepend(htmlManual);
		$('div#'+game+'BonusesPendingList').prepend(html);

		processSwitchItemsDisplay();
		
		updateCount(gameID);
	}
	
	function processBonusClick(el)
	{
		if(el.hasClass('inProgress')) return;
		
		var gameID = el.attr('gameID');
		var game =  bkP.gamesData[gameID].systemName;
		
		el.disableContextMenu().unbind('click').addClass('inProgress');
		
		var img = el.find('img:last');
		
		if(img.attr('src'))
			var orig = img.attr('src');
		else if(img.attr('nosrc'))
		{
			var orig = img.attr('nosrc');
			img.removeAttr('nosrc');
		}
		else
			var orig = '';
		
		img.attr('orig-src', orig).attr('src', 'gfx/dl.gif').css({ width: '64px', height: '64px'});
		
		var obj = {
					id: el.attr('id'),
					url: el.attr('url'),
					game: game,
					type: 'bonus',
					title: el.attr('search-title')
				}
		
		
		if(game == 'farmville')
		{
			if(bkP.options.games[gameID].useRandomTimeoutOnBonuses)
			{
				bkP.xhrFarmQueue.push(obj);
				updateQueueCount();
				return true;
			}	
		}	
		
		bkP.xhrQueue.push(obj);
		updateQueueCount();
	}
	
	function processRequestClick(el)
	{
		if(el.hasClass('inProgress')) return;
		
		var gameID = el.attr('gameID');
		var game =  bkP.gamesData[gameID].systemName;
		
		el.disableContextMenu().unbind('click').addClass('inProgress');
		
		
		var img = el.find('img:last');
		
		if(img.attr('src'))
			var orig = img.attr('src');
		else if(img.attr('nosrc'))
		{
			var orig = img.attr('nosrc');
			img.removeAttr('nosrc');
		}
		else
			var orig = '';
			
		img.attr('orig-src', orig).attr('src', 'gfx/dl.gif').css({ width: '64px', height: '64px'});
		
		var obj = {
					id: el.attr('id'),
					post: el.attr('postData'),
					game: game,
					type: 'request',
					title: el.attr('search-title')
				}
		
		bkP.xhrQueue.push(obj);
		updateQueueCount();
	}
	
	function ReceiveVisibleBonuses(gameID)
	{
		ReceivePendingBonuses(gameID, true);
	}
	
	function ReceivePendingBonuses(gameID, onlyVisible)
	{
		if(onlyVisible != undefined)
			var addParam = ':visible';
		else
			var addParam = '';
		
		var game = bkP.gamesData[gameID].systemName;
		$('#'+game+'BonusesPendingList').children('div'+addParam).not('.inProgress').each(function(){
			processBonusClick($(this));
		});
	}
	
	function ReceiveVisibleGifts(gameID)
	{
		ReceivePendingRequests(gameID, true);
	}
	
	function ReceivePendingRequests(gameID, onlyVisible)
	{
		if(onlyVisible != undefined)
			var addParam = ':visible';
		else
			var addParam = '';
		
		var game = bkP.gamesData[gameID].systemName;
		$('#'+game+'RequestsPendingList').children('div'+addParam).not('.inProgress').each(function(){
			processRequestClick($(this));
		});
	}
	
	function bonusError(id, data)
	{
		var el = $('#'+id);
		el.find('.deleteIcon').remove();
		el.find('img:last').attr('src', 'gfx/90px-cancel.png');
		
		var error_text = (typeof(data.error_text) != 'undefined' && data.error_text != '' ? ' <img src="gfx/info.png" title="'+data.error_text+'" />' : '');
		
		el.attr('error', data.error);		
		el.find('.bonusError').html('('+data.error+' error)'+error_text);
		
		var gameID = el.attr('gameID');
		var game = bkP.gamesData[gameID].systemName;
		
		updateQueueCount();
		
		if(isScreenLocked)
		{
			addDataToScreenLocked('bonusErrorFinish', id, data);
		}
		else
		{
			bonusErrorFinish(id, data);
		}
	}
	
	function bonusErrorFinish(id, data)
	{
		var el = $('#'+id);
		var gameID = el.attr('gameID');
		var game = bkP.gamesData[gameID].systemName;
		
		if(data.error == 'connection' || data.error == 'other')
		{
			setTimeout(function() {
				el.enableContextMenu().removeClass('inProgress');
				el.find('img:last').attr('src', el.find('img:last').attr('orig-src'));
			}, 1000);
		}
		else
		{
			setTimeout(function()
			{
				el.addClass('withDesc');
				el.unbind('mousedown').unbind('contextmenu').unbind('mouseup').die().prependTo('#'+game+'FailedBonusesList');
				el.removeClass('hide').attr('time', data.time).find('.timeAgo').text(format_time_ago(data.time));
				el.find('.description').removeClass('hide');
				el.removeClass('processBonusClick');
				
				if(data.error == 'receiving')
				{
					el.addClass('processManualBonusClick').css('cursor', 'pointer !important').attr('title', bkP.getMsg('ClickToOpenThisItemInNewTab'));
				}
				
				updateCount(gameID);
				
				processSwitchItemsDisplay();
			}, 1000);
		}
	}
	
	function bonusSuccess(id, data)
	{
		var el = $('#'+id);
		el.find('.deleteIcon').remove();
		el.find('img:last').attr('src', 'gfx/90px-check.png');
		
		var gameID = el.attr('gameID');
		var game = bkP.gamesData[gameID].systemName;
		
		updateQueueCount();
		
		if(isScreenLocked)
		{
			addDataToScreenLocked('bonusSuccessFinish', id, data);
		}
		else
		{
			bonusSuccessFinish(id, data);
		}
	}
	
	function bonusSuccessFinish(id, data)
	{
		var el = $('#'+id);
		var gameID = el.attr('gameID');
		var game = bkP.gamesData[gameID].systemName;
	
		setTimeout(function() 
		{
			el.addClass('withDesc');
			el.prependTo('#'+game+'BonusesHistoryList');
			el.removeClass('hide').removeClass('inProgress');

			if(data.image !== '')
			{
				el.find('img:last').attr('src', data.image);
			}
			else
			{
				el.find('img:last').attr('src', el.find('img:last').attr('orig-src'));
			}
			
			
			if(data.title != '')
			{
				el.find('.title').text(data.title);
			}
			
			
			var infoAdd = '';
			
			if(typeof(data.thanks) != 'undefined' && data.thanks != '')
			{
				infoAdd = JSON.stringify(data.thanks);
			}
			
			el.find('.bonusError').css('height', '23px').html(addLikeRow(false, infoAdd, false));
			
			if(typeof el.attr('isLiked') !== 'undefined')
			{
				updateLikeState('#'+id, 0);
			}
			
			if(typeof el.attr('isCommented') !== 'undefined')
			{
				updateCommentState('#'+id, 0);
			}
			
			el.find('.description').removeClass('hide');
			
			if(data.text != '')
			{
				el.attr('title', data.text);
				el.find('.description').removeClass('hide').html(data.text);
			}
			
			el.removeClass('processBonusClick');
			el.attr('time', data.time).find('.timeAgo').text(format_time_ago(data.time));
			updateCount(gameID);
			
			processSwitchItemsDisplay();
			
		}, 1000);
	}
	
	function addLikeRow(like, sendBack, comm, isRequest)
	{
		
		var sendBackHtml = '';

		if(sendBack != '' && sendBack != null && sendBack != '""')
		{
			var sendBackJson = JSON.parse(sendBack);
			
			if(typeof(sendBackJson.sent) == 'undefined')
			{
				var img3 = 'gfx/sendback.png';
				var enabled = 'true';
				var cursor = 'cursor: pointer';
				var className = 'sendBack';
				var desc = bkP.getMsg('ClickToSendThankYouGift');
			}
			else
			{
				var img3 = 'gfx/23check.png';
				var enabled = 'false';
				var cursor = '';
				var className = '';
				var desc = bkP.getMsg('ThankYouGiftAlreadySent');
			}
			sendBackHtml = '<img src="'+img3+'" class="'+className+'" isEnabled="'+enabled+'" title="'+desc+'" style="'+cursor+'"><span style="display: none">'+sendBack+'</span>';
		}
		
		if(typeof(isRequest) != 'undefined')
		{
			return '<div style="position: relative"><div style="position: absolute;left:48;">'+sendBackHtml+'</div></div>';
		}
		else
		{
			if(like == false || like == 0)
			{
				var img = 'gfx/like.png';
				var addClassLike = '';
			}
			else
			{
				var img = 'gfx/like-off.png';
				var addClassLike = ' disabledLike';
			}
			
			if(comm == false || comm == 0)
			{
				var img2 = 'gfx/comment.png';
				var addClassComm = '';
			}
			else
			{
				var img2 = 'gfx/comment-off.png';
				var addClassComm = ' disabledComment';
			}
		
			return '<div style="position: relative"><div style="position: absolute;left:0;"><img src="'+img+'" class="likeBonus'+addClassLike+'" title="'+bkP.getMsg('ClickToLike')+'" style="cursor: pointer"></div><div style="position: absolute;left:60;">'+sendBackHtml+'</div><div style="position: absolute;right:0;"><img src="'+img2+'" class="commentBonus'+addClassComm+'" title="'+bkP.getMsg('ClickToPostComment')+'" style="cursor: pointer"></div></div>';
		}
	}
	
	function requestError(id, data)
	{
		var el = $('#'+id);
		el.find('.deleteIcon').remove();
		el.find('img:last').attr('src', 'gfx/90px-cancel.png');
		
		var error_text = (typeof(data.error_text) != 'undefined'  && data.error_text != ''  ? ' <img src="gfx/info.png" title="'+data.error_text+'" />' : '');
		
		el.attr('error', data.error);		
		el.find('.bonusError').html('('+data.error+' error)'+error_text);
		
		var gameID = el.attr('gameID');
		var game = bkP.gamesData[gameID].systemName;
		
		updateQueueCount();
		
		if(isScreenLocked)
		{
			addDataToScreenLocked('requestErrorFinish', id, data);
		}
		else
		{
			requestErrorFinish(id, data);
		}	
		
	}
	
	function requestErrorFinish(id, data)
	{
		var el = $('#'+id);
		var gameID = el.attr('gameID');
		var game = bkP.gamesData[gameID].systemName;
		
		if(data.error == 'connection')
		{
			setTimeout(function() {
				el.enableContextMenu().removeClass('inProgress');
				el.find('img:last').attr('src', el.find('img:last').attr('orig-src'));
			}, 1000);
		}
		else
		{
			setTimeout(function() {
				el.addClass('withDesc').unbind('mousedown').unbind('contextmenu').unbind('mouseup').die().prependTo('#'+game+'FailedGiftsList');
				el.attr('time', data.time).find('.timeAgo').text(format_time_ago(data.time));
				el.find('.description').removeClass('hide');
				el.removeClass('processRequestClick');
				
				if(data.error == 'receiving')
				{
					el.addClass('processManualRequestClick').css('cursor', 'pointer !important').attr('title', bkP.getMsg('ClickToOpenThisItemInNewTab'));
				}				
				updateCount(gameID);
			}, 1000);
		}
	}
	
	function requestSuccess(id, data)
	{
		var el = $('#'+id);
		el.find('.deleteIcon').remove();
		el.find('img:last').attr('src', 'gfx/90px-check.png');
		
		var gameID = el.attr('gameID');
		var game = bkP.gamesData[gameID].systemName;
		
		updateQueueCount();
		
		if(isScreenLocked)
		{
			addDataToScreenLocked('requestSuccessFinish', id, data);
		}
		else
		{
			requestSuccessFinish(id, data);
		}
		
	}
	
	
	function requestSuccessFinish(id, data)
	{
		var el = $('#'+id);
		var gameID = el.attr('gameID');
		var game = bkP.gamesData[gameID].systemName;
		
		setTimeout(function() {
			el.prependTo('#'+game+'RequestsHistoryList');
			el.addClass('withDesc').removeClass('inProgress');
			el.removeClass('processRequestClick');
			
			if(data.image !== '')
			{
				el.find('img:last').attr('src', data.image);
			}
			else
			{
				el.find('img:last').attr('src', el.find('img:last').attr('orig-src'));
			}
			
			
			if(data.title != '')
			{
				el.find('.title').text(data.title);
			}

			
			var infoAdd = '';
			
			if(typeof(data.thanks) != 'undefined' && data.thanks != '')
			{
				if(data.thanks != '' && typeof(data.thanks.gift) != 'undefined' && data.image != '')
				{
					if(el.attr('isMissingImage'))
						$.getJSON('http://rzadki.eu/projects/fgs/jsonp/gifts.php?callback=?', {gameID: gameID, gift: data.thanks.gift, image: data.image});
				}
				infoAdd = JSON.stringify(data.thanks);
			}
			
			el.find('.bonusError').css('height', '23px').html(addLikeRow(false, infoAdd, false, true));
			
			if(typeof el.attr('SendbackInProgress') !== 'undefined')
			{
				updateSendbackState('#'+id);
			}
			
			el.find('.title').next('span').removeClass('hide').text(data.text);
			el.attr('time', data.time).find('.timeAgo').text(format_time_ago(data.time));
			updateCount(gameID);
		}, 1000);
	}
	
	function ClearManualBonuses(gameID, onlyVisible)
	{
		var game = bkP.gamesData[gameID].systemName;
		
		if(onlyVisible != undefined)
			var addParam = ':visible';
		else
			var addParam = '';
		
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var delReqArr = [];
					var delBonArr = [];

					$('#'+game+'ManualBonusesList').children('div'+addParam).each(function()
					{
						var elID = $(this).attr('id');
						if($(this).hasClass('manualRequest'))
						{
							var postData = $(this).attr('postData');
							var pos1 = postData.indexOf('&actions%5B');
							
							var postData = postData.slice(0,pos1);
							postData += '&actions[reject]=Ignore';
							bkP.emptyUnwantedGifts(postData);
							
							delReqArr.push(elID);
						}
						else
						{
							delBonArr.push(elID);
						}
						
						$(this).remove();
					});
					
					while(delReqArr.length > 0)
					{
						var tmpArr = delReqArr.slice(0,500);
						
						var str = ' where id = "'+tmpArr.join('" or id = "')+'" ';
						bkP.database.deleteItemArray('requests', gameID, str, 0);
						
						delReqArr = delReqArr.slice(500);						
					}
					
					while(delBonArr.length > 0)
					{
						var tmpArr = delBonArr.slice(0,500);
						
						var str = ' where id = "'+tmpArr.join('" or id = "')+'" ';
						bkP.database.deleteItemArray('bonuses', gameID, str, 0);
						
						delBonArr = delBonArr.slice(500);						
					}
					
					processSwitchItemsDisplay();
					updateCount(gameID);
					
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}
		});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearVisibleBonuses(gameID)
	{
		ClearPendingBonuses(gameID, true);
	}
	
	function ClearVisibleManualBonuses(gameID)
	{
		ClearManualBonuses(gameID, true);
	}
	
	function ClearPendingBonuses(gameID, onlyVisible)
	{
		if(onlyVisible != undefined)
			var addParam = ':visible';
		else
			var addParam = '';
			
			
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					var delArr = [];

					$('#'+game+'BonusesPendingList').children('div'+addParam).not('.inProgress').each(function()
					{
						delArr.push($(this).attr('id'));
						$(this).remove();
					});
					
					while(delArr.length > 0)
					{
						var tmpArr = delArr.slice(0,500);
						
						var str = ' where id = "'+tmpArr.join('" or id = "')+'" ';
						bkP.database.deleteItemArray('bonuses', gameID, str, 0);
						
						delArr = delArr.slice(500);						
					}
					updateCount(gameID);
					processSwitchItemsDisplay();
					
					
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearVisibleGifts(gameID)
	{
		ClearPendingRequests(gameID, true);
	}
	
	function ClearPendingRequests(gameID, onlyVisible)
	{
		if(onlyVisible != undefined)
			var addParam = ':visible';
		else
			var addParam = '';
			
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
		
					var delArr = [];
					
					$('#'+game+'RequestsPendingList').children('div'+addParam).not('.inProgress').each(function()
					{
						var postData = $(this).attr('postData');
						var pos1 = postData.indexOf('&actions%5B');
						
						var postData = postData.slice(0,pos1);
						postData += '&actions[reject]=Ignore';
						$(this).remove();
						bkP.emptyUnwantedGifts(postData);
						delArr.push($(this).attr('id'));
					});
					
					while(delArr.length > 0)
					{
						var tmpArr = delArr.slice(0,500);
						
						var str = ' where id = "'+tmpArr.join('" or id = "')+'" ';
						bkP.database.deleteItemArray('requests', gameID, str, 0);
						
						delArr = delArr.slice(500);						
					}
					
					processSwitchItemsDisplay();
					updateCount(gameID);

					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearCollectedBonuses(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					$('#'+game+'BonusesHistoryList').html('<br style="clear:both" />');
					updateCount(gameID);
					bkP.database.clearTable('bonuses', gameID, 1);
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearPendingBonusesOtherError(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('Clear')+' "Other errors"');
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					
					var delArr = [];
					
					
					$('#'+game+'BonusesPendingList').children('div').not('.inProgress').each(function()
					{
					
						if($(this).attr('error') == 'other')
						{
							delArr.push($(this).attr('id'));
							$(this).remove();
						}
					});
					
					while(delArr.length > 0)
					{
						var tmpArr = delArr.slice(0,500);
						
						var str = ' where id = "'+tmpArr.join('" or id = "')+'" ';
						bkP.database.deleteItemArray('bonuses', gameID, str, 0);
						
						delArr = delArr.slice(500);						
					}
					updateCount(gameID);
					processSwitchItemsDisplay()
					
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearCollectedBonusesLimitError(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('Clear')+' "Limit errors"');
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					$('#'+game+'FailedBonusesList').children('div').each(function(){
						if($(this).attr('error') == 'limit')
						{
							$(this).remove();
						}
					});
					//('<br style="clear:both" />');
					bkP.database.clearLimitErrors(gameID);
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearAllFailedBonuses(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					$('#'+game+'FailedBonusesList').children('div').each(function(){
						$(this).remove();
					});
					bkP.database.clearFailedBonuses(gameID);
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearAllFailedRequests(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					$('#'+game+'FailedGiftsList').children('div').each(function(){
						$(this).remove();
					});
					//('<br style="clear:both" />');
					bkP.database.clearFailedGifts(gameID);
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearCollectedBonusesReceivingError(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('Clear')+' "Receiving errors"');
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					$('#'+game+'FailedBonusesList').children('div').each(function()
					{
						if($(this).attr('error') == 'receiving')
						{
							$(this).remove();
						}
					});
					//('<br style="clear:both" />');
					bkP.database.clearReceivingErrors(gameID);
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearCollectedRequestsReceivingError(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('Clear')+' "Receiving errors"');
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					$('#'+game+'FailedGiftsList').children('div').each(function(){
						if($(this).attr('error') == 'receiving')
						{
							$(this).remove();
						}
					});
					//('<br style="clear:both" />');
					bkP.database.clearRequestReceivingErrors(gameID);
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearCollectedRequestsLimitError(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('Clear')+' "Limit errors"');
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					$('#'+game+'FailedGiftsList').children('div').each(function(){
						if($(this).attr('error' ) == 'limit')
						{
							$(this).remove();
						}
					});
					//('<br style="clear:both" />');
					bkP.database.clearRequestLimitErrors(gameID);
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	
	function ClearCollectedRequests(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					$('#'+game+'RequestsHistoryList').html('<br style="clear:both" />');
					updateCount(gameID);
					bkP.database.clearTable('requests', gameID, 1);
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function ClearSentFreeGifts(gameID)
	{
		$('#dialog-confirm').dialog({
			open: function()
			{
				$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
				$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
			},
			buttons:
			{
				Clear: function()
				{
					var game = bkP.gamesData[gameID].systemName;
					$('#'+game+'SendFreeGiftsHistoryList').html('<br style="clear:both" />');
					bkP.database.clearTable('freegifts', gameID);
					$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
		}});
		
		$('#dialog-confirm').dialog('open');
	}
	
	function addNewRequest(data2)
	{
		var htmls = {};
		var htmlsManual = {};
		
		if(isScreenLocked)
		{
			addDataToScreenLocked('addNewRequest', '', data2);
			return;
		}
		
		var ids = [];
		
		$(data2).each(function(ind,data)
		{
			var itID = parseInt(data[0]);
			
			if($.inArray(itID, ids) != -1 || $('#'+itID).length > 0)
				return;
			
			ids.push(itID);
			
			var v = {	id: data[0],	title: data[2],	text: data[3],	image: data[4], post: data[5],	time: data[6]	}
			
			var gameID = data[1];
			
			if(typeof(htmls[gameID]) == 'undefined')
			{
				htmls[gameID] = '';
				htmlsManual[gameID] = '';
			}			
			
			if(checkIfRequestIsManual(gameID, v.text))
			{
				htmlsManual[gameID] += getNewManualRequestRow(gameID, v);
			}
			else
			{		
				htmls[gameID] += getNewRequestRow(gameID, v);
			}
		});

		
		for(var tmp in htmls)
		{
			var game = bkP.gamesData[tmp].systemName;
			$('div#'+game+'ManualBonusesList').prepend(htmlsManual[tmp]);
			$('div#'+game+'RequestsPendingList').prepend(htmls[tmp]);
		}
		
		
		processSwitchItemsDisplay();
		
		updateCount();
	}


	function calcage(secs, num1, num2)
	{
		s = ((Math.floor(secs/num1))%num2).toString();
		if (s.length < 2)
			s = "0" + s;
		return s;
	}

	
	function updateCount(gameID)
	{
		var processList = {};

		if(typeof(gameID) == 'undefined')
		{
			for(var idd in bkP.gamesData)
			{
				if(bkP.options.games[idd].enabled)
				{
					processList[idd] = true;
				}
			}
		}
		else
		{
			processList[gameID] = true;
		}
		
		for(var idd2 in processList)
		{		
			var game = bkP.gamesData[idd2].systemName;
			
			var totCount = 0;
			
			var bCount = $('#'+game+'BonusesPendingList > div').length;
			var rCount = $('#'+game+'RequestsPendingList > div').length;
			var mCount = $('#'+game+'ManualBonusesList > div').length;
			
			totCount += bCount;
			totCount += rCount;
			totCount += mCount;
			
			
			$('a[href="#'+game+'BonusesPending"]').find('span').text(bCount);
			$('a[href="#'+game+'RequestsPending"]').find('span').text(rCount);
			$('a[href="#'+game+'ManualBonuses"]').find('span').text(mCount);
			$('label[for="'+game+'Selected"]').find('.badgeDiv').removeClass('hide').children('span').text(totCount);
		}
	}


	function getBonusHistoryRow(v)
	{
		if(!v.error_text)
		{
			var errorText = '';
		}
		else
		{
			var errorText = v.error_text;
		}

		var error_text = (errorText != '' ? ' <img src="gfx/info.png" title="'+errorText+'" />' : '');		
		
		var err = (v.error == error_text ? addLikeRow(v.like_bonus, v.resend_gift, v.comment_bonus) : '('+v.error+' error)'+error_text)
		
		if(v.image == 'undefined' && error_text == '')
		{
			var showImage = 'gfx/90px-check.png';
		}
		else
		{
			var showImage = v.image;
		}
		
		var addClass = '';
		
		
		if(v.error == 'receiving')
		{
			addClass = ' processManualBonusClick ';
		}
		else if(v.error == '')
		{
			addClass = ' noErrorClass ';
		}
		
		return '<div id="'+v.id+'" error='+v.error+' gameID="'+v.gameID+'" time="'+v.time+'" url="'+v.url+'" title="'+v.text+'" class="bonusItem withDesc disabled updateTimeAgo '+addClass+'"><span class="timeAgo">'+format_time_ago(v.time)+'</span><span class="bonusError">'+err+'</span><img src="'+showImage+'"><span class="title">'+v.title+'</span><span class="description">'+v.text+'</span></div>';
	}
	
	function getRequestHistoryRow(v)
	{
		if(!v.error_text)
		{
			var errorText = '';
		}
		else
		{
			var errorText = v.error_text;
		}
		
		var error_text = (errorText != '' ? ' <img src="gfx/info.png" title="'+errorText+'" />' : '');
		
		
		var err = (v.error == error_text ? addLikeRow(false, v.resend_gift, false, true) : '('+v.error+' error)'+error_text);
		
		var addClass = '';
		if(v.error == 'receiving')
		{
			addClass = ' processManualRequestClick ';
		}
		else if(v.error == '')
		{
			addClass = ' noErrorClass ';
		}
		
		return '<div id="'+v.id+'" error="'+v.error+'" gameID="'+v.gameID+'" time="'+v.time+'" postData="'+v.post+'" class="withDesc requestItem disabled updateTimeAgo'+addClass+'"><span class="timeAgo">'+format_time_ago(v.time)+'</span><span class="bonusError">'+err+'</span><img src="'+v.image+'" onError="processImageError(this)"><span class="title">'+v.title+'</span><span class="description">'+v.text+'</span></div>';
	}
	
	function friendsLoaded(gameID, status)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'NeighborsSearchList';
		
		if(!status)
			var html = '<h3 class="center">'+bkP.getMsg('ThereWasAProblemTryAgainLater')+'</h3>';
		else
		{
			if(status.length == 0)
				var html = '<h3 class="center">'+bkP.getMsg('NoPeopleLookingForNeighborsInThisGame')+'</h3>';
			else
			{
				var html = '<h3 class="center">'+bkP.getMsg('ThesePeopleAreLookingForNeighbors')+':</h3>';
				$(status).each(function(k,v)
				{
					html+='<div class="friendsList"><a href="http://www.facebook.com/addfriend.php?id='+v+'&fromFGS='+escape(bkP.gamesData[gameID].name)+'" class="friendLink" target="_blank">'+v+'</a></div>';
				});
				html+= '<br style="clear: both" />';
			}
		}
		$('div#'+game+opt, '#'+game+'Game').find('.searchForPeopleList').html(html);
	}
	
	function CheckIfNeighborsAvailable(gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'NeighborsSearchList';
		
		if(!$(".gameListOnNeighborsSearch[gameID='"+gameID+"']").is(':checked'))
		{
			alert(bkP.getMsg('MustCheckListMeOnNeighborsSearchBeforeSearch'));
			return;
		}
		
		$('div#'+game+opt, '#'+game+'Game').html('<h2 class="center">Found people:</h2> <div class="searchForPeopleList"><h3 class="center"><img src="gfx/loading.gif"><br />Looking for people who are not already your neighbors... Please wait...</h3></div>');
		
		bkP.searchForNeighbors.Step1(gameID);
	}
	
	function neighborsLoaded(users, gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';
		
		$('.sendingGiftProgress','div#'+game+opt).remove();
		
		if(!users)
		{
			var html = '<h3 class="center">'+bkP.getMsg('ThereWasAProblemTryAgainLater')+'</h3>';
			$('.sendToNeighboursList','div#'+game+opt).html(html);
		}
		else
		{
			var favArr = [], norArr = [];
			var favObj = {}, norObj = {}
			var favCnt = norCnt = 0;
			
			$(users).each(function(k,val)
			{
				for(var i in val)
				{
					var id = i;
				}
				var v = val[id];
				
				if($.inArray(id, bkP.options.games[gameID].favourites) != -1)
				{
					favObj[id] = favCnt;
					favCnt++;
					favArr.push([
						'<img src="icons/favourite.png" gameID="'+gameID+'" neighID="'+id+'" class="toggleFavourite">',
						'<a href="http://www.facebook.com/profile.php?id='+id+'" target="_blank">'+v.name+'</a>',
						'<span class="hide">0</span>'+bkP.getMsg('Never'),
						'<span class="hide">0</span>'+bkP.getMsg('Never'),
						'<span class="hide">0</span>'+bkP.getMsg('Never'),
						'<span class="hide">0</span>0',
						'<span class="hide">0</span>0',
						'<span class="hide">0</span>0',
						'<input type="checkbox" value="'+id+'" gameID="'+gameID+'" neighID="'+id+'" class="selectNeighborToSend" name="neighArr[]">'
					]);
				}
				else
				{
					norObj[id] = norCnt;
					norCnt++;
					
					norArr.push([
						'<img src="icons/favourite-bw.png" gameID="'+gameID+'" neighID="'+id+'" class="toggleFavourite">', 
						'<a href="http://www.facebook.com/profile.php?id='+id+'" target="_blank">'+v.name+'</a>',
						'<span class="hide">0</span>'+bkP.getMsg('Never'),
						'<span class="hide">0</span>'+bkP.getMsg('Never'),
						'<span class="hide">0</span>'+bkP.getMsg('Never'),
						'<span class="hide">0</span>0',
						'<span class="hide">0</span>0',
						'<span class="hide">0</span>0',
						'<input type="checkbox" value="'+id+'" gameID="'+gameID+'" neighID="'+id+'" class="selectNeighborToSend" name="neighArr[]">'
					]);
				}	
			});
			
			var data = 
			{
				nor: norObj,
				fav: favObj,
				norArr: norArr,
				favArr: favArr
			}
			
			loadNeighborsStats(gameID, data);
		}
		
		
	}
	
	function LoadNeighborsList(gameID)
	{
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';
		
		$('div#'+game+opt, '#'+game+'Game').html('<h2 class="center hide">Favourite neighbors:</h2> <div class="sendToFavouritesList hide"></div> <h2 class="center hide">Gifts list:</h2> <div class="hide sendToGiftsList"></div> <h2 class="center">Neighbors list:</h2> <div class="sendToNeighboursList"><h3 class="center"><img src="gfx/loading.gif"><br />Loading your neighbors... Please wait...</h3></div>');
		
		listGifts(gameID);
		
		setTimeout(function(){ bkP.ListNeighbours(gameID) }, 100);
	}


function startup()
{
	$('#currentVersion').text(bkP.currentVersion);
	prepareGameSelector();
	processGameListOnNeighborsSearch();
}


function prepareGameSelector()
{
	for(var gameID in bkP.gamesData)
	{
		addIconToGameSelector(gameID);
		addIconToOptionsMenu(gameID);
	}
	
	$('#gameOptionsTab').append('<br style="clear: both" />');
	
	// dodaj chat i opcje
	$('<input type="radio" class="gameSelectorInput" name="gameSelectorInput" id="chatSelected" /><label gameName="Chat" for="chatSelected"><img src="icons/menu/chat.png"></label>').appendTo('#gameSelector');
	
	$('<input type="radio" class="gameSelectorInput" name="gameSelectorInput" id="contactSelected" /><label gameName="Contact" for="contactSelected"><img src="icons/menu/48contact.png"></label>').appendTo('#gameSelector');
	
	$('<input type="radio" class="gameSelectorInput" name="gameSelectorInput" id="optionsSelected" /><label gameName="Options" for="optionsSelected"><img src="icons/menu/options.png"></label>').appendTo('#gameSelector');
	
	$('#gameSelector').children('label').contextMenu({
			menu: 'myMenuGameIcon'
		}, function(action, el, pos)
		{
			if(action == 'hideIcon')
			{
				var gameID = $(el).prev().attr('gameID');
				$(el).addClass('hide');
				bkP.options.games[gameID].hiddenIcon = true;					
				bkP.saveOptions();
				
				if(!$('#options').hasClass('hide'))
					loadOptionsData();					
			}
			else if(action == 'goToGame')
			{
				var gameID = $(el).prev().attr('gameID');
				bkP.openURI(bkP.gamesData[gameID].link, false);
			}
	});
	
	$('#gameSelector').children('[gamename="Contact"], [gamename="Chat"], [gamename="Options"]').disableContextMenu();
	
	$('#gameSelector').children('label').tooltip({
		delay: 0,
		track: true,
		bodyHandler: function()
			{
				if($(this).is('[gamename="Contact"], [gamename="Chat"], [gamename="Options"]'))
					return '<h2>'+bkP.getMsg($(this).attr("gameName"))+'</h2>'; 
				else
					return '<h2>'+$(this).attr("gameName")+'</h2>'; 
			}, 
		positionLeft: true,
		showURL: false
	});
		
	$("#gameSelector").buttonset();
}

function addIconToOptionsMenu(gameID)
{
	var d =  bkP.gamesData[gameID];
	var e =  bkP.options.games[gameID];
	
	var addSpecOpt = '<br style="line-height: 19px;" />';
	
	if(gameID == '102452128776')
	{
		addSpecOpt = '<input type="checkbox" '+(!e.enabled ? 'disabled="disabled"':'')+' '+(e.useRandomTimeoutOnBonuses ? 'checked="checked"':'')+'  class="gameUseRandomTimeoutOnBonuses" gameID="'+gameID+'" /> <label>Use random timeout on bonuses</label><br />';
	}
	
	var el = $('<div gameName="'+d.name+'" class="optionsGameDiv"><img style="float: left" src="icons/menu/48'+d.systemName+'.png" /><span style="float: left;">'
	+ '<input type="checkbox" '+(e.enabled ? 'checked="checked"':'')+' class="gameEnabledBox" gameID="'+gameID+'" /> <label>Enable <strong>'+d.name+'</strong></label><br />'
	+ '<input type="checkbox" '+(!e.enabled ? 'disabled="disabled"':'')+'  '+(gameID == bkP.options.defaultGame ? 'checked="checked"':'')+' class="gameDefaultBox" gameID="'+gameID+'" /> <label>Go to this game on FGS startup</label><br />'
	+ '<input type="checkbox" '+(!e.enabled ? 'disabled="disabled"':'')+'  '+(e.likeBonus ? 'checked="checked"':'')+' class="gameLikeBonusBox" gameID="'+gameID+'" /> <label>Auto like bonuses</label><br />'
	+ '<input type="checkbox" '+(!e.enabled ? 'disabled="disabled"':'')+'  '+(e.sendbackGift ? 'checked="checked"':'')+' class="gameSendbackGiftBox" gameID="'+gameID+'" /> <label>Send thank you gift</label><br />'
	+ '<input type="checkbox" '+(!e.enabled ? 'disabled="disabled"':'')+'  '+(e.hideFromFeed ? 'checked="checked"':'')+' class="gameHideFromFeedBox" gameID="'+gameID+'" /> <label>Hide collected bonuses from FB feed</label><br />'
	+ '<input type="checkbox" '+(!e.enabled ? 'disabled="disabled"':'')+'  '+(e.hideFromFeedLimitError ? 'checked="checked"':'')+' class="gameHideFromFeedLimitErrorBox" gameID="'+gameID+'" /> <label>Hide "limit errors" from FB feed</label><br />'
	+ '<input type="checkbox" '+(!e.enabled ? 'disabled="disabled"':'')+' '+(e.listOnSearch? 'checked="checked"':'')+'  class="gameListOnNeighborsSearch" gameID="'+gameID+'" /> <label>List me on neighbors search</label><br />'
	+ addSpecOpt
	+ '</span></div>');

	var gs = $('#gameOptionsTab');	
	
	if(gs.children('div').length == 0)
	{
		gs.append(el);
	}
	else
	{
		var added = false;
		gs.children('div').each(function(){
			if($(this).attr('gameName') > d.name)
			{
				$(this).before(el);
				added = true;
				return false;
			}
		});
		if(!added)
			gs.append(el);
	}
}

function addIconToGameSelector(gameID)
{
	var d =  bkP.gamesData[gameID];
	var e =  bkP.options.games[gameID];

	var el = $('<input type="radio" class="gameSelectorInput" name="gameSelectorInput" gameID="'+gameID+'" id="'+d.systemName+'Selected" /><label gameName="'+d.name+'" for="'+d.systemName+'Selected"><div class="badgeDiv hide"><span></span></div><img nosrc="icons/menu/48'+d.systemName+'.png" alt="'+d.name+'" /></label>');

	if(!e.enabled)
		el.addClass('hide');
	else
	{
		el.find('img').attr('src', el.find('img').attr('nosrc'));
		addGameMenu(gameID);
	}

	var gs = $('#gameSelector');	
	
	if(gs.children('label').length == 0)
	{
		gs.append(el);
	}
	else
	{
		var added = false;
		gs.children('label').each(function(){
			if($(this).attr('gameName') > d.name)
			{
				$(this).prev('input').before(el);
				added = true;
				return false;
			}
		});
		if(!added)
			gs.append(el);
	}
}


function addGameMenu(gameID)
{
	var game = bkP.gamesData[gameID].systemName;
	
		
	var el = $('<div id="'+game+'Game" gameID="'+gameID+'" class="gameContent hide"><ul></ul></div>');
	var elOpt = el.children('ul');
	
	$(bkP.gamesData[gameID].buttons).each(function(k,id)
	{
		var butName = bkP.submenuButtons[id].name;
		
		elOpt.append('<li><a href="#'+game+id+'" gameID="'+gameID+'">'+butName+'</a></li>');
		el.append('<div id="'+game+id+'"><div class="submenu center"><div class="submenuInfo"></div></div><div id="'+game+id+'List"><br style="clear:both" /></div></div>');
		
		var curEl = $('#'+game+id, el);
		
		if(id == 'BonusesPending' || id == 'ManualBonuses' || id == 'RequestsPending')
		{
			if(id == 'BonusesPending')
				if(bkP.gamesData[gameID].bonusNotice != undefined)
					curEl.prepend('<div style="font-size: 1.5em; font-weight:bolder;text-align: center;color: red;padding: 5px; border: 1px dotted red;margin-bottom: 10px;">'+bkP.gamesData[gameID].bonusNotice+'</div>');

			var addSearch = '<h3>'+bkP.getMsg('SimpleFilter')+'</h3> <input type="text" class="filterBonusText" /> <select class="searchWhat"><option value="1">'+bkP.getMsg('OnlyTitles')+'</option><option value="2">'+bkP.getMsg('OnlyDescriptions')+'</option><option value="0" selected="selected">'+bkP.getMsg('Both')+'</option>';
		
			curEl.find('.submenu').css('margin', '0 300px').append('<div style="float: left;position: absolute; left: 15px; width: 290px;" class="showAllButtonDiv"><span class="showAllText"></span><input type="checkbox" id="'+game+'ShowAll'+id+'" gameID="'+gameID+'" class="ShowAllItems" /><label for="'+game+'ShowAll'+id+'">'+bkP.getMsg('ShowAllItems')+'</label> <input type="checkbox" id="'+game+'ShowDescriptions'+id+'" gameID="'+gameID+'" class="ShowDescriptions" '+ ( bkP.options.showDescriptionsOnStartup == 1 ? ' checked="checked"' : '')+' /><label for="'+game+'ShowDescriptions'+id+'">'+bkP.getMsg('ShowDescriptions')+'</label><br />'+addSearch+'<br /></div>');
		}
		
		if(id == 'NeighborsSearch')
		{
			curEl.find('#'+game+id+'List').html('<h2 class="center">'+bkP.getMsg('ClickAboveToStartSearchingForNeighbors')+'</h2>');
		}
		
		if(id == 'SendFreeGifts')
		{
			curEl.find('#'+game+id+'List').html('<h2 class="center">'+bkP.getMsg('ClickAboveToLoadYourNeighborsList')+'</h2>');
		}
		
		for(var id2 in bkP.submenuButtons[id].submenu)
		{
			var sub = bkP.submenuButtons[id].submenu[id2];
			if(id == 'SendFreeGifts')
			{
				var disabled = (id2 == 'LoadNeighborsList' ? '' : ' hide ');
			}
			else
				var disabled = '';
			
			curEl.find('.submenu').append('<button class="submenuButton'+disabled+'" id="'+game+id2+'" gameID="'+gameID+'" sysID="'+id2+'">'+sub.name+'</button>');
		}
		curEl.find('.submenu').children('button').button();
	});
	
	el.insertBefore('#chat');
	el.tabs({
		show: function(event, ui)
		{
			updateTimeAgo(ui.panel.id);
			if(ui.tab.hash.match(/gameOptionsTab$/gi))
				return processLoadFiltersForGame($(ui.tab).attr('gameID'), ui.panel.id);
			
			processSwitchItemsDisplay();
		}
	});
}

function checkIconsCountInGameSelector(dontSwitchGame)
{
	if($('#gameSelector').find('label:visible').length == 3)
	{
		processGameSelectorInput($('#gameSelector').find('input:visible:last').attr('checked', 'checked'));
		$('#gameSelector').prepend('<h2>'+bkP.getMsg('NoGamesSelectPleaseSelectSomeBelow')+'<br /><br /></h2>');
		$("#gameSelector").buttonset('refresh');
	}
	else
	{
		if(bkP.options.defaultGame != 0 && !dontSwitchGame)
		{
			var el = $('#gameSelector').children('input[gameID="'+bkP.options.defaultGame+'"]');
			if(!el.hasClass('hide'))
			{
				processGameSelectorInput(el.attr('checked', 'checked'));
				$("#gameSelector").buttonset('refresh');
			}
		}
		$('#gameSelector').children('h2').remove();
	}
}

function processGameSelectorInput(el)
{
	$('.gameContent:visible').addClass('hide');
	
	$('#currentTabName').html(' - ' + $(el).next().attr('gameName'));
	
	clearInterval(chatInterval);
	chatInterval = null;
	
	
	if($(el).attr('id') == 'chatSelected')
	{
		$('#chat').removeClass('hide');
		$('.shouts', '#chat').html('');
		
		setTimeout(function() { readChat(true); }, 1);
		var chatInterval = setInterval(readChat, bkP.options.checkChatTimeout*1000);
		return;
	}
	else if($(el).attr('id') == 'contactSelected')
	{
		$('#contact').removeClass('hide');
	}
		else if($(el).attr('id') == 'optionsSelected')
	{
		$('#options').removeClass('hide');
	}
	else
	{
		var d =  bkP.gamesData[$(el).attr('gameID')];		
		
		var tab = $('#'+d.systemName+'Game').removeClass('hide');
		
		processSwitchItemsDisplay();
		updateTimeAgo(tab.children('div').not('.hide').attr('id'));
		return;
	}
}

function processGameEnabledInput(el)
{
	var gameID = $(el).attr('gameID');
	var chk = $(el).is(':checked');
	
	var ico = $('#gameSelector').find('input[gameID="'+gameID+'"]').next('label').find('img');
	
	if(chk)
	{
		el.siblings().removeAttr('disabled');
		ico.closest('label').removeClass('hide');
		ico.attr('src', ico.attr('nosrc'));
		addGameMenu(gameID);
	}
	else
	{
		el.siblings().attr('disabled', 'disabled');
		var d =  bkP.gamesData[$(el).attr('gameID')];
		$('#'+d.systemName+'Game').remove();
		ico.closest('label').addClass('hide');
	}
	checkIconsCountInGameSelector(true);
		
	bkP.options.games[gameID].enabled = chk;
	switchEnabled(gameID, true);
	bkP.saveOptions();
	bkP.restartRequests();
}

function processGameDefaultInput(el)
{
	var gameID = $(el).attr('gameID');
	
	if($(el).is(':checked'))
	{
		bkP.options.defaultGame = gameID;
		$(".gameDefaultBox").not(el).removeAttr('checked');
	}
	else
	{
		bkP.options.defaultGame = 0;
	}
	bkP.saveOptions();
}

function processGameLikeBonusInput(el)
{
	bkP.options.games[$(el).attr('gameID')].likeBonus = $(el).is(':checked') ? true : false;
	bkP.saveOptions();
}

function processGameSendbackGiftInput(el)
{
	bkP.options.games[$(el).attr('gameID')].sendbackGift = $(el).is(':checked') ? true : false;
	bkP.saveOptions();
}

function processGameHideFromFeedInput(el)
{
	bkP.options.games[$(el).attr('gameID')].hideFromFeed = $(el).is(':checked') ? true : false;
	bkP.saveOptions();
}

function processGameHideFromFeedLimitErrorInput(el)
{
	bkP.options.games[$(el).attr('gameID')].hideFromFeedLimitError = $(el).is(':checked') ? true : false;
	bkP.saveOptions();
}

function processGameUseRandomTimeoutOnBonuses(el)
{
	bkP.options.games[$(el).attr('gameID')].useRandomTimeoutOnBonuses = $(el).is(':checked') ? true : false;
	bkP.saveOptions();
}

function processGameListOnNeighborsSearch(el)
{
	if(typeof(el) != 'undefined')
	{
		bkP.options.games[$(el).attr('gameID')].listOnSearch = $(el).is(':checked') ? true : false;
		bkP.saveOptions();
	}
	
	var enabledArr = [];
	
	$('#gameSelector').children('label:visible').each(function()
	{ 
		var gameID = $(this).prev().attr('gameID');
		if($('.gameListOnNeighborsSearch[gameID="'+gameID+'"]').is(':checked'))
			enabledArr.push(gameID);
	});
	
	$.getJSON('http://rzadki.eu/projects/fgs/jsonp/neighbors.php?callback=?', {action: 'update', games: enabledArr.join(), userID: bkP.userID});
}

function switchEnabled(gameID, reload)
{
	var game = bkP.gamesData[gameID].systemName;
	var enabled  = bkP.options.games[gameID].enabled;

	if(enabled == false)
	{
		if(typeof(reload) != 'undefined')
		{
			/*
			bkP.database.clearByGameID(gameID);
			bkP.options.games[gameID] = bkP.defaultGameOptions;
			*/
			delete bkP.bonusLoadingProgress[gameID];
			updateCount();
			bkP.stopBonusesForGame(gameID);
		}
	}
	else
	{
		if(typeof(reload) != 'undefined')
		{
			loadBonuses(gameID);
			bkP.startBonusesForGame(gameID);
		}
	}
}

function loadComments()
{
	var el = $('#defaultCommentsMessages');
	el.html('');
	
	if(bkP.options.defaultCommentsMessages.length == 0)
	{
		el.html('You have currently no comments setup to post on successful bonuses.');
	}
	else
	{
		$(bkP.options.defaultCommentsMessages).each(function(i,msg)
		{
			el.append('<div style="float: left; width: 250px;margin-right: 10px;"><img src="icons/delete-16.png" delIndex="'+i+'" style="cursor: pointer;width: 10px;height: 10px" class="deleteComment" title="'+bkP.getMsg('DeleteComment')+'"> '+msg+'</div>');
		});	
	}

	el.append('<br style="clear:both" /><textarea style="margin-top: 50px;" class="newCommentText"></textarea><button id="saveNewComment">'+bkP.getMessage('SaveComment')+'</button>');
}

function processSaveNewComment(el)
{
	var txt = el.prev('textarea').val();
	if(txt != '')
	{
		var msg = txt;
		bkP.options.defaultCommentsMessages.push(msg);
		bkP.saveOptions();
		loadComments();
	}
}

function processDeleteComment(el)
{
	bkP.options.defaultCommentsMessages.splice($(el).attr('delIndex'),1);
	bkP.saveOptions();
	
	$(el).parent().remove();
	loadComments();
}

function processSubmenuClick(el)
{
	try
	{
		window[$(el).attr('sysID')]($(el).attr('gameID'));

	}
	catch(e)
	{
		//console.log(e);
	}
}

function processLoadFiltersForGame(gameID, opt)
{
	var arr = bkP.options.games[gameID].filter;
	arr.sort();
	
	var game = bkP.gamesData[gameID].systemName;
	
	if(arr.length == 0)
	{
		$('div#'+opt+'List').html('<h4>You have currently no filters.</h4>To add some: Right click unwanted bonus and select "Don\'t collect this type of bonuses"</h4><br style="clear:both" />');
	}
	else
	{
		
		var html = '';
		
		for(var i = 0; i < arr.length; i++)
		{
			var v = arr[i];
			html += '<div style="float: left; width: 250px;margin-right: 10px;"><img src="icons/delete-16.png" delIndex="'+i+'" gameID="'+gameID+'" style="cursor: pointer;width: 10px;height: 10px" class="deleteFilter" title="'+bkP.getMsg('DeleteFilter')+'"> '+v+'</div>';
		}
		
		html+= '<br style="clear:both" />';
		$('div#'+opt+'List').html(html);
	}
}

function processDeleteFilter(el)
{
	var gameID = $(el).attr('gameID');
	var game = bkP.gamesData[gameID].systemName;
	
	bkP.options.games[gameID].filter.splice($(el).attr('delIndex'),1);
	bkP.saveOptions();
	
	$(el).parent().remove();
	processLoadFiltersForGame(gameID, game+'GameOptionsTab');
}

function processSwitchItemsDisplay()
{
	var gc = $('.gameContent:visible');
	
	if(gc == undefined)
		return;
	
	var gameID = gc.attr('gameID');

	var target = gc.children('div:visible').attr('id');
	
	if(target == undefined)
		return;
	
	if(!target.match(/(BonusesPending|ManualBonuses|RequestsPending)$/gi))
		return;	
	
	var game = bkP.gamesData[gameID].systemName;
	var el = $('#'+target+'List');
	var total = el.children('div').length;
	var elSub  = el.prev('.submenu');
	
	if(elSub.height() < 85)
	{
		elSub.height(85);
	}

	var showDesc = $('input.ShowDescriptions', elSub).button().is(':checked');
	var textFilter = $('input.filterBonusText', elSub).val();
	var filterType = parseInt($('select.searchWhat option:selected', elSub).val());
	el.children('div').addClass('hide');
	
	
	if(textFilter == '' || textFilter == ' ')
	{
		var matchingItems = el.children('div');
	}
	else
	{
		var found = 0;
		
		var matchingItems = el.children('div').filter(function()
		{
			var tstTitle = $('.title:Contains("'+textFilter+'")', this).length > 0 ? true : false;
			var tstDesc  = $('.description:Contains("'+textFilter+'")', this).length > 0 ? true : false;
			
			
			switch(filterType)
			{
				case 0:
					if(tstTitle || tstDesc)
					{
						found++;
						return true;
					}
					return false;
				break;
				
				case 1:
					if(tstTitle)
					{
						found++;
						return true;
					}
					return false;
				break;
				
				case 2:
					if(tstDesc)
					{
						found++;
						return true;
					}
					return false;
				break;
			}
			return false;
		});
	}
	
	if($('input.ShowAllItems', elSub).button().is(':checked'))
	{
		$('input.ShowAllItems', elSub).prev('span').html('<h3>'+bkP.getMsg('ShowingAllItems')+'</h3>');
		matchingItems.removeClass('hide');		
		appendSrcToImages(el.attr('id'));
		switchDescriptions(el.attr('id'), showDesc);
		return;
	}
	
	if(total > 100 && total == matchingItems.length)
	{
		$('input.ShowAllItems', elSub).prev('span').html('<h3>'+bkP.getMsg('Showing100ItemsTotalX', [total])+'</h3>');
		$('input.ShowAllItems', elSub).next().removeClass('hide');
	}
	else if(total > 100 && total != matchingItems.length)
	{
		$('input.ShowAllItems', elSub).prev('span').html('<h3>'+bkP.getMsg('ShowingXItemsFilteredX', [matchingItems.length, (total-matchingItems.length)])+'</h3>');
		$('input.ShowAllItems', elSub).next().removeClass('hide');
	}
	else
	{
		$('input.ShowAllItems', elSub).prev('span').html('<h3>'+bkP.getMsg('ShowingAllItems')+'</h3>');
		$('input.ShowAllItems', elSub).next().addClass('hide');
	}
	matchingItems.slice(0, 99).removeClass('hide');

	appendSrcToImages(el.attr('id'));
	switchDescriptions(el.attr('id'), showDesc);
	
	el.removeClass('hide');
}


function switchDescriptions(id, test)
{
	if(test)
	{
		$('#'+id).children('div').not('.hide').not('.withDesc').addClass('withDesc').find('.description').removeClass('hide');
	}
	else
	{
		$('#'+id).children('div.withDesc').not('.hide').removeClass('withDesc').find('.description').addClass('hide');
	}
}

function appendSrcToImages(id)
{
	$('#'+id).children('div').not('.hide').each(function(k,v)
	{
		var img = $(this).find('img[nosrc]');
		if(img.length > 0)
		{
			img.attr('src', img.attr('nosrc')).removeAttr('nosrc');
		}
	});
}
	
function windowFocus()
{
	bkP.newElements = 0;
	bkP.updateIcon();
	bkP.giftlistFocus = true;
}

function windowBlur()
{
	bkP.giftlistFocus = false;
}

function updateTimeAgo(target)
{
	var olderThanTime = bkP.options.deleteHistoryOlderThan;
	var olderBonusThanTime = bkP.options.deleteOlderThan;
	
	$('.updateTimeAgo', '#'+target).each(function()
	{
		var time = $(this).attr('time');
		var timeAgo = format_time_ago(time)
		$(this).find('.timeAgo').html(timeAgo);
	
		if($(this).hasClass('inProgress'))
		{
			return;
		}
		
		if($(this).hasClass('bonusItem') || $(this).hasClass('manualBonus'))
		{
			if($(this).hasClass('disabled'))
			{
				if(olderThanTime == 0)
				{
					return;
				}
				
				if(compareTime($(this).attr('time'), olderThanTime))
				{
					$(this).remove();
				}
			}
			else
			{
				if(olderBonusThanTime == 0)
				{
					return;
				}
				
				if(compareTime($(this).attr('time'), olderBonusThanTime))
				{
					var gameIDtmp = $(this).attr('gameID');
					$(this).remove();
					updateCount(gameIDtmp);
				}
			}
		}
		else if($(this).hasClass('requestItem'))
		{
			if($(this).hasClass('disabled'))
			{
				if(olderThanTime == 0)
				{
					return;
				}
				
				if(compareTime($(this).attr('time'), olderThanTime))
				{
					$(this).remove();
				}
			}
		}
		else if($(this).hasClass('freegiftHistory'))
		{
			if(olderThanTime == 0)
			{
				return;
			}
			
			if(compareTime($(this).attr('time'), olderThanTime))
			{
				$(this).remove();
			}
		}
	});
}

function onMouseDownTest(e)
{
	var el = $(e.srcElement || e.target);

	if(e.which == 2)
	{
		if(el.closest('div').hasClass('processBonusClick') && el.closest('div').hasClass('hasContextMenu')  && !el.closest('div').hasClass('inProgress'))
		{
			bkP.openURI(el.closest('div').attr('url'), true);
			processSingleBonusRemove(el.closest('div'));
			
		}
		e = e ? e : window.event;
		if(e.stopPropagation)
			e.stopPropagation();
		if(e.preventDefault)
			e.preventDefault();
		e.cancelBubble = true;
		e.cancel = true;
		e.returnValue = false;
		return false;
	}
}

	$(function()
	{
		startup();
		
		$( "#dialog-loading" ).dialog({
			resizable: false,
			width: 400,
			height: 350,
			modal: true,
			position: [Math.floor(($(this).width()-400)/2),200],
			autoOpen: true
		});
		
		$( "#progressbar" ).progressbar({
			value: 0
		});
		
		loadBonuses();
		
		$(window).click(function(e)
		{
			var el = $(e.srcElement || e.target);
			
			/*
			if(e.which == 2)
			{
				if(el.closest('div').hasClass('processBonusClick') && el.closest('div').hasClass('hasContextMenu'))
				{
					bkP.openURI(el.closest('div').attr('url'), true);
					processSingleBonusRemove(el.closest('div'));
					
				}
				return true;
			}
			*/
			
			if(e.which != 1) return true;
			
			if(el.hasClass('gameSelectorInput'))
				return processGameSelectorInput(el);
			else if(el.hasClass('gameEnabledBox'))
				return processGameEnabledInput(el);
			else if(el.hasClass('gameDefaultBox'))
				return processGameDefaultInput(el);
			else if(el.hasClass('gameLikeBonusBox'))
				return processGameLikeBonusInput(el);
			else if(el.hasClass('gameSendbackGiftBox'))
				return processGameSendbackGiftInput(el);
			else if(el.hasClass('gameHideFromFeedBox'))
				return processGameHideFromFeedInput(el);
			else if(el.hasClass('gameHideFromFeedLimitErrorBox'))
				return processGameHideFromFeedLimitErrorInput(el);
			else if(el.hasClass('gameListOnNeighborsSearch'))
				return processGameListOnNeighborsSearch(el);
			else if(el.hasClass('gameUseRandomTimeoutOnBonuses'))
				return processGameUseRandomTimeoutOnBonuses(el);
			else if(el.hasClass('deleteComment'))
				return processDeleteComment(el);
			else if(el.hasClass('toggleFavourite'))
				return processToggleFavourite(el);
			else if(el.hasClass('selectNeighborToSend'))
				return processSelectNeighborToSend(el);
			else if(el.hasClass('submenuButton'))
				return processSubmenuClick(el);
			else if(el.parent().hasClass('submenuButton'))
				return processSubmenuClick(el.parent());
			else if(el.hasClass('deleteFilter'))
				return processDeleteFilter(el);
			else if(el.hasClass('ShowAllItems') || el.hasClass('ShowDescriptions'))
				return processSwitchItemsDisplay();
			
			else if(el.hasClass('deleteIcon'))
				return processSingleBonusRemove(el.closest('div'));
			
			else if(el.closest('div').hasClass('processManualRequestClick'))
				return processManualRequestClick(el.closest('div'));
				
			else if(el.closest('div').hasClass('processManualBonusClick'))
				return processManualBonusClick(el.closest('div'));
			
			else if(el.closest('div').hasClass('processBonusClick'))
				return processBonusClick(el.closest('div'));
			else if(el.closest('div').hasClass('processRequestClick'))
				return processRequestClick(el.closest('div'));
			
			else if(el.hasClass('likeBonus'))
				return processLikeBonus(el);
			else if(el.hasClass('sendBack'))
				return processSendBack(el);
			else if(el.hasClass('commentBonus'))
				return processCommentBonus(el);
				
			if(el.attr('id') == 'saveNewComment')
				return processSaveNewComment(el);
		})
			.focus(windowFocus)
			.blur(windowBlur)
			.unload(windowBlur);
		
		windowFocus();

		$('#options').tabs({show: function(event, ui) { if(ui.index == 1) loadComments(); }});

		setTimeout(readNotices, 1);
		setInterval(readNotices, 300000);
		
		$('#checkBonusesTimeout > option[value="'+bkP.options.checkBonusesTimeout+'"]').attr('selected', 'selected');
		$('#checkBonusesTimeout').change(function()
		{
			bkP.options.checkBonusesTimeout = $('option:selected', this).val();
			bkP.restartBonuses();
			bkP.saveOptions();
		});
		
		$('#checkChatTimeout > option[value="'+bkP.options.checkChatTimeout+'"]').attr('selected', 'selected');
		$('#checkChatTimeout').change(function()
		{
			bkP.options.checkChatTimeout = $('option:selected', this).val();
			bkP.saveOptions();
		});
		
		
		$('#breakStartupLoadingOption > option[value="'+bkP.options.breakStartupLoadingOption+'"]').attr('selected', 'selected');
		$('#breakStartupLoadingCount > option[value="'+bkP.options.breakStartupLoadingCount+'"]').attr('selected', 'selected');
		$('#breakStartupLoadingTime > option[value="'+bkP.options.breakStartupLoadingTime+'"]').attr('selected', 'selected');
		
		if(bkP.options.breakStartupLoadingOption == 0)
			$('#breakStartupLoadingCount').css('display', 'block');
		else
			$('#breakStartupLoadingTime').css('display', 'block');

		$('#breakStartupLoadingCount').change(function()
		{
			bkP.options.breakStartupLoadingCount = $('option:selected', this).val();
			bkP.saveOptions();
		});
		
		$('#breakStartupLoadingTime').change(function()
		{
			bkP.options.breakStartupLoadingTime = $('option:selected', this).val();
			bkP.saveOptions();
		});
		
		$('#breakStartupLoadingOption').change(function()
		{
			bkP.options.breakStartupLoadingOption = $('option:selected', this).val();
			
			if($('option:selected', this).val() == 0)
			{
				$('#breakStartupLoadingTime').css('display', 'none');
				$('#breakStartupLoadingCount').css('display', 'block');
			}
			else
			{
				$('#breakStartupLoadingCount').css('display', 'none');
				$('#breakStartupLoadingTime').css('display', 'block');
			}
			bkP.saveOptions();
		});
		
		
		
		$('#deleteOlderThan > option[value="'+bkP.options.deleteOlderThan+'"]').attr('selected', 'selected');
		$('#deleteOlderThan').change(function()
		{
			bkP.options.deleteOlderThan = $('option:selected', this).val();
			bkP.saveOptions();
		});
		
		$('#deleteHistoryOlderThan > option[value="'+bkP.options.deleteHistoryOlderThan+'"]').attr('selected', 'selected');
		$('#deleteHistoryOlderThan').change(function()
		{
			bkP.options.deleteHistoryOlderThan = $('option:selected', this).val();
			bkP.saveOptions();
		});
		
		$('#displayXbonuses > option[value="'+bkP.options.displayXbonuses+'"]').attr('selected', 'selected');
		$('#displayXbonuses').change(function()
		{
			bkP.options.displayXbonuses = $('option:selected', this).val();
			bkP.saveOptions();
		});
		
		$('#collectXbonusesAtTheSameTime > option[value="'+bkP.options.collectXbonusesAtTheSameTime+'"]').attr('selected', 'selected');
		$('#collectXbonusesAtTheSameTime').change(function()
		{
			bkP.options.collectXbonusesAtTheSameTime = $('option:selected', this).val();
			bkP.saveOptions();
		});
		
		$('#showDescriptionsOnStartup > option[value="'+bkP.options.showDescriptionsOnStartup+'"]').attr('selected', 'selected');
		$('#showDescriptionsOnStartup').change(function()
		{
			bkP.options.showDescriptionsOnStartup = $('option:selected', this).val();
			bkP.saveOptions();
		});
		
		$('.filterBonusText').data('timeout', null).keyup(function()
		{
            clearTimeout(jQuery(this).data('timeout'));
            jQuery(this).data('timeout', setTimeout(processSwitchItemsDisplay, 500));
        });		
		
		
		$(".showContext").live('mouseenter', function()
		{
			if($(this).hasClass('hasContextMenu'))
			{
				return;
			}
			$(this).addClass('hasContextMenu').contextMenu({
				menu: 'myMenu'
			}, function(action, el, pos) {
				
				if(action == 'receive')
				{
					processBonusClick(el);
				}
				else if(action == 'receiveSimilar')
				{
					el.parent().find('div[search-title="'+el.attr('search-title')+'"]').not('.inProgress').each(function(){
						processBonusClick($(this));
					});
				}
				else if(action == 'delete')
				{
					processSingleBonusRemove(el);
				}
				else if(action == 'deleteSimilar')
				{
					$('#dialog-confirm').dialog({
						open: function()
						{
							$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
							$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
						},
						buttons:
						{
							Clear: function()
							{
								el.parent().find('div[search-title="'+el.attr('search-title')+'"]').not('.inProgress').each(function()
								{
									$(this).remove();
								});
								bkP.database.deleteItemByTitle('bonuses', el.attr('gameID'), el.attr('search-title'), 0);
								updateCount(el.attr('gameID'));
								
								$( this ).dialog( "close" );
							},
							Cancel: function() {
								$( this ).dialog( "close" );
							}
					}});
					
					$('#dialog-confirm').dialog('open');
				}
				else if(action == 'stopCollect')
				{
					$('#dialog-confirm').dialog({
						buttons:
						{
							"Stop collecting": function()
							{
								bkP.options.games[el.attr('gameID')].filter.push(el.attr('search-title'));
								bkP.saveOptions();
								el.parent().find('div[search-title="'+el.attr('search-title')+'"]').not('.inProgress').each(function()
								{
									$(this).remove();
								});
								bkP.database.deleteItemByTitle('bonuses', el.attr('gameID'), el.attr('search-title'), 0);
								updateCount(el.attr('gameID'));
								
								$( this ).dialog( "close" );
							},
							Cancel: function() {
								$( this ).dialog( "close" );
							}
					}});
					
					$('#dialog-confirm').dialog('open');
				}
				else if(action == 'copylink')
				{
					bkP.copyLink(el.attr('url'));
				}
				else if(action == 'openAndDelete')
				{
					bkP.openURI(el.attr('url'), true);
					processSingleBonusRemove(el);
				}
				else if(action == 'debug')
				{
					bkP.openURI(el.attr('url'), true);
				}
			});
		});
		
		$(".showContextRequests").live('mouseenter', function()
		{
			if($(this).hasClass('hasContextMenu'))
			{
				return;
			}
			$(this).addClass('hasContextMenu').contextMenu({
				menu: 'myMenuRequests'
			}, function(action, el, pos) {
				
				if(action == 'receive')
				{
					processRequestClick(el);
				}
				else if(action == 'receiveSimilar')
				{
					el.parent().find('div[search-title="'+el.attr('search-title')+'"]').not('.inProgress').each(function(){
						processRequestClick($(this));
					});
				}
				else if(action == 'delete')
				{
					var postData = el.attr('postData');
					var pos1 = postData.indexOf('&actions%5B');
					
					var postData = postData.slice(0,pos1);
					postData += '&actions[reject]=Ignore';
					el.remove();
					bkP.database.deleteItem('requests', el.attr('gameID'), el.attr('id'), 0);
					updateCount(el.attr('gameID'));
					
					bkP.emptyUnwantedGifts(postData);
				}
				else if(action == 'deleteSimilar')
				{
					$('#dialog-confirm').dialog({
						open: function()
						{
							$(this).parent().find('.ui-dialog-buttonset').find('span:first').text(bkP.getMsg('ClearEverything'));
							$(this).parent().find('.ui-dialog-buttonset').find('span:last').text(bkP.getMsg('Cancel'));
						},
						buttons:
						{
							Clear: function()
							{
								el.parent().find('div[search-title="'+el.attr('search-title')+'"]').not('.inProgress').each(function()
								{
									var postData = $(this).attr('postData');
									var pos1 = postData.indexOf('&actions%5B');
									
									var postData = postData.slice(0,pos1);
									postData += '&actions[reject]=Ignore';
									$(this).remove();
									bkP.emptyUnwantedGifts(postData);
								});
								
								bkP.database.deleteItemByTitle('requests', el.attr('gameID'), el.attr('origTitle'), 0);
								updateCount(el.attr('gameID'));
								
								$( this ).dialog( "close" );
							},
							Cancel: function() {
								$( this ).dialog( "close" );
							}
					}});
					
					$('#dialog-confirm').dialog('open');
				}
				else if(action == 'debug')
				{
					bkP.prepareLinkForGame('', el.attr('id'), el.attr('postData'), true);
					//el.remove();
				}
			});
		});
		
		
		$(".showContextManual").live('mouseenter', function()
		{
			if($(this).hasClass('hasContextMenu'))
			{
				return;
			}
			$(this).addClass('hasContextMenu').contextMenu({
				menu: 'myMenuManualBonuses'
			}, function(action, el, pos)
			{
				if(action == 'delete')
				{
					el.remove();
					bkP.database.deleteItem('bonuses', el.attr('gameID'), el.attr('id'), 0);
					updateCount(el.attr('gameID'));
				}
				else if(action == 'deleteSimilar')
				{
					$('#dialog-confirm').dialog({
						buttons:
						{
							"Delete all items": function()
							{
								el.parent().find('div[search-title="'+el.attr('search-title')+'"]').not('.inProgress').each(function()
								{
									$(this).remove();
								});
								bkP.database.deleteItemByTitle('bonuses', el.attr('gameID'), el.attr('search-title'), 0);
								updateCount(el.attr('gameID'));
								$( this ).dialog( "close" );
							},
							Cancel: function() {
								$( this ).dialog( "close" );
							}
					}});
					
					$('#dialog-confirm').dialog('open');
				}
				else if(action == 'stopCollect')
				{
					$('#dialog-confirm').dialog({
						buttons:
						{
							"Stop collecting": function()
							{
								bkP.options.games[el.attr('gameID')].filter.push(el.attr('search-title'));
								bkP.saveOptions();
								el.parent().find('div[search-title="'+el.attr('search-title')+'"]').not('.inProgress').each(function()
								{
									$(this).remove();
								});
								bkP.database.deleteItemByTitle('bonuses', el.attr('gameID'), el.attr('search-title'), 0);
								updateCount(el.attr('gameID'));
								
								$( this ).dialog( "close" );
							},
							Cancel: function() {
								$( this ).dialog( "close" );
							}
					}});
					$('#dialog-confirm').dialog('open');
				}
				else if(action == 'copylink')
				{
					bkP.copyLink(el.attr('url'));
				}
			});
		});
		
		$(".selectGiftToSend").live('mouseenter', function()
		{
			if($(this).hasClass('hasContextMenu'))
			{
				return;
			}
			$(this).addClass('hasContextMenu').contextMenu({
				menu: 'myMenuDefaultGift'
			}, function(action, el, pos)
			{
				if(action == 'selectDefault')
				{
					el.siblings(".selectGiftToSend").removeClass('selected');
					el.addClass('selected');
					
					bkP.options.games[el.attr('gameID')].defaultGift = el.attr('giftID');					
					bkP.saveOptions();
				}
			}).click(function(){
				$(this).siblings("div.selectGiftToSend").removeClass('selected');
				$(this).addClass('selected');
			});
		});

		$( "#dialog-confirm" ).dialog({
			resizable: false,
			autoOpen: false,
			height:140,
			modal: true
		});
		
		$( "#dialog-error" ).dialog({
			resizable: false,
			autoOpen: false,
			height:'auto',
			modal: true
		});
		
		$( "#dialog-normal" ).dialog({
			resizable: false,
			autoOpen: false,
			height:'auto',
			modal: true
		});
		
		
		
		
		$('#lockScreen').button().click(function()
		{
			isScreenLocked = $(this).is(':checked');
			
			if($(this).is(':checked'))
			{
				$(this).button('option', 'label', 'Screen is: LOCKED (no new bonuses will show until you unlock it)');
			}
			else
			{
				$(this).button('option', 'label', 'Screen is: UNLOCKED (click to lock)');
				updateCount();
				var procArr = screenLockedData;
				screenLockedData = [];
				
				$(procArr).each(function(k,v)
				{
					if(v.id == '')
						window[v.callback](v.data);
					else
						window[v.callback](v.id, v.data);					
				});
			}
		});
		
		
		$('#receiveBonusesAllGames').button().click(function()
		{
			for(var idd in bkP.gamesData)
			{
				if(bkP.options.games[idd].enabled)
				{
					ReceivePendingBonuses(idd);
				}
			}
		});
		
		$('#receiveGiftsAllGames').button().click(function()
		{
			for(var idd in bkP.gamesData)
			{
				if(bkP.options.games[idd].enabled)
				{
					ReceivePendingRequests(idd);
				}
			}
		});
		
		$('#stopReceivingQueue').button().click(function()
		{
			$(bkP.stopQueue()).each(function(k,v)
			{
				var id = v.id;
				
				if(v.type == 'bonus')
				{
					$('#'+id).enableContextMenu().removeClass('inProgress');
					$('#'+id).find('img:last').attr('src', $('#'+id).find('img:last').attr('orig-src'));
				}
				else
				{
					$('#'+id).enableContextMenu().removeClass('inProgress');
					$('#'+id).find('img:last').attr('src', $('#'+id).find('img:last').attr('orig-src'));
				}
			});
			
			updateQueueCount();
		});
		
		$('#exportSettings').click(function()
		{
			var set = jQuery.extend(true,{},bkP.options);
			var cleanSet = {};
			
			for(var id in set)
			{
				if(typeof(bkP.defaultOptions[id]) != 'undefined')
				{
					cleanSet[id] = set[id];
				}
			}	
			var set = JSON.stringify(cleanSet);

			$('#settingsTextarea').click(function(){
				$(this).focus().select();
			});
			
			$('#settingsTextarea').val(set).trigger('click');			
		});
		
		$('#importSettings').click(function()
		{
			var txt = $('#settingsTextarea').val();
			
			try
			{
				if(txt == '') throw {}
				var set = JSON.parse(txt);

				var cleanSet = {}
				
				for(var id in set)
				{
					if(typeof(bkP.defaultOptions[id]) != 'undefined')
					{
						cleanSet[id] = set[id];
					}
				}
				
				alert('New data loaded. Use FGS icon to open this page again');
				bkP.options = bkP.jQuery.extend(true,{}, bkP.defaultOptions,	cleanSet);
				bkP.FBloginError = null;
				bkP.updateIcon();
				bkP.sendView('closeAndOpen');
			}
			catch(e)
			{
				alert('There was a problem importing data, make sure you have copied whole text from your file.');
			}			
		});
		
	});
	
	function updateQueueCount()
	{
		$('#queueItemsCount').text((bkP.xhrQueue.length+bkP.xhrFarmQueue.length));
	}

	function processSelectNeighborToSend(e)
	{
		var gameID = $(e).attr('gameID');
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';

		var count = parseInt($('input[name="neighArr[]"]:checked', 'div#'+game+opt).length);

		if(count > 25)
		{
			return false;
		}
	}
	
	function processSingleBonusRemove(el)
	{
		el.remove();
		bkP.database.deleteItem('bonuses', el.attr('gameID'), el.attr('id'), 0);
		updateCount(el.attr('gameID'));
	}
	
	function processToggleFavourite(e)
	{
		var srcEl	= $(e);
		var gameID 	= srcEl.attr('gameID');
		var uID		= srcEl.attr('neighID');
		var srcEl	= srcEl.closest('tr');
		
		var game = bkP.gamesData[gameID].systemName;
		var opt = 'SendFreeGiftsList';
				
		var idx = bkP.options.games[gameID].favourites.indexOf(uID);
				
		if(idx == -1)
		{
			bkP.options.games[gameID].favourites.push(uID);
			
			var arr =
				[
					'<img src="icons/favourite.png" gameID="'+gameID+'" neighID="'+uID+'" class="toggleFavourite">',
					srcEl.children('td:nth-child(2)').html(),
					srcEl.children('td:nth-child(3)').html(),
					srcEl.children('td:nth-child(4)').html(),
					srcEl.children('td:nth-child(5)').html(),
					srcEl.children('td:nth-child(6)').html(),
					srcEl.children('td:nth-child(7)').html(),
					srcEl.children('td:nth-child(8)').html(),
					srcEl.children('td:nth-child(9)').html()
				];

			$('.favouritesTable', 'div#'+game+opt).dataTable().fnAddData(arr);
			$('.neighborsTable', 'div#'+game+opt).dataTable().fnDeleteRow( srcEl[0] );
		}
		else
		{
			bkP.options.games[gameID].favourites.splice(idx, 1);
			
			var arr =
				[
					'<img src="icons/favourite-bw.png" gameID="'+gameID+'" neighID="'+uID+'" class="toggleFavourite">', 
					srcEl.children('td:nth-child(2)').html(),
					srcEl.children('td:nth-child(3)').html(),
					srcEl.children('td:nth-child(4)').html(),
					srcEl.children('td:nth-child(5)').html(),
					srcEl.children('td:nth-child(6)').html(),
					srcEl.children('td:nth-child(7)').html(),
					srcEl.children('td:nth-child(8)').html(),
					srcEl.children('td:nth-child(9)').html()
				];
			
			$('.neighborsTable', 'div#'+game+opt).dataTable().fnAddData(arr);
			$('.favouritesTable', 'div#'+game+opt).dataTable().fnDeleteRow( srcEl[0] );
		}
		bkP.saveOptions();
	}
	
	function processLikeBonus(el)
	{
		if(!el.hasClass('disabledLike'))
		{
			var bonusID = el.parent().parent().parent().parent().attr('id');
			el.addClass('disabledLike').attr('src', 'gfx/act_indicator.gif');
			bkP.likeBonus(bonusID);
		}
	}

	function processCommentBonus(el)
	{
		if(bkP.options.defaultCommentsMessages.length == 0)
		{
			alert('You must setup comment messages first in options tab');
		}
		else
		{
			if(!el.hasClass('disabledComment'))
			{
				var randNum = Math.floor(Math.random()*(bkP.options.defaultCommentsMessages.length));
				var bonusID = el.parent().parent().parent().parent().attr('id');
				el.addClass('disabledComment').attr('src', 'gfx/act_indicator.gif');
				bkP.commentBonus(bonusID, bkP.options.defaultCommentsMessages[randNum]);
			}
		}
	}
	
	function processSendBack(el)
	{
		if(!el.hasClass('disabledSendback'))
		{
			var bonusID = el.parent().parent().parent().parent().attr('id');
			el.addClass('disabledSendback').attr('src', 'gfx/act_indicator.gif');

			var gameID =  el.parent().parent().parent().parent().attr('gameID');
			
			var tempData = JSON.parse(el.next().text());
			
			var params = {
				gift: tempData.gift,
				gameID:	gameID,
				sendTo: [tempData.destInt],
				sendToName: tempData.destName,
				thankYou: true,
				bonusID: bonusID,	
				isRequest: el.parent().parent().parent().parent().hasClass('bonusItem') ? false : true
			};
			
			var game = bkP.gamesData[gameID].systemName;
			
			bkP[game].Freegifts.Click(params);
		}
	}
	
	function updateSendback(bonusID, success, isDailyLimit)
	{
		if(success)
		{
			$('img.sendBack', '#'+bonusID).addClass('disabledSendback').removeClass('sendBack').attr('src', 'gfx/23check.png').css('cursor', 'default').attr('title', bkP.getMsg('ThankYouGiftAlreadySent'));
		}
		else if(isDailyLimit)
		{
			$('img.sendBack', '#'+bonusID).addClass('disabledSendback').removeClass('sendBack').attr('src', 'gfx/23error.png').css('cursor', 'default').attr('title', bkP.getMsg('ThankYouGiftAlreadySentToday'));
		}
		else
		{
			$('img.sendBack', '#'+bonusID).removeClass('disabledSendback').attr('src', 'gfx/23error.png').attr('title', bkP.getMsg('ErrorWhileSendingThankYouGift'))
		}
	}
	
	function updateLike(bonusID, error)
	{
		
		var img = $('img.likeBonus', '#'+bonusID);
		
		if(img.length > 0)
		{
			updateLikeState('#'+bonusID, error);
		}
		else
		{
			if(error == 0)
			{
				$('#'+bonusID).attr('isLiked', 1);
			}
		}
	}
	
	function updateLikeState(selector, error)
	{
		if(error == 0)
		{
			$('img.likeBonus', selector).addClass('disabledLike').removeClass('likeBonus').attr('src', 'gfx/like-off.png').css('cursor', 'default').attr('title', bkP.getMsg('YouHaveAlreadyLikedThis'));
		}
		else
		{
			$('img.likeBonus', selector).removeClass('disabledLike').attr('src', 'gfx/like.png');
		}
	}
	
	function updateCommentState(selector, error)
	{
		if(error == 0)
		{
			$('img.commentBonus', selector).addClass('disabledComment').removeClass('commentBonus').attr('src', 'gfx/comment-off.png').css('cursor', 'default').attr('title', bkP.getMsg('YouHaveAlreadyPostedCommentOnThis'));
		}
		else
		{
			$('img.commentBonus', selector).removeClass('disabledComment').attr('src', 'gfx/comment.png');
		}
	}
	
	function updateComment(bonusID, error)
	{
		var img = $('img.commentBonus', '#'+bonusID);
		
		if(img.length > 0)
		{
			updateCommentState('#'+bonusID, error);
		}
		else
		{
			if(error == 0)
			{
				$('#'+bonusID).attr('isCommented', 1);
			}
		}
	}
	
	function changeSendbackState(bonusID)
	{
		var img = $('img.sendBack', '#'+bonusID);
		
		if(img.length > 0)
		{
			updateSendbackState('#'+bonusID);
		}
		else
		{
			$('#'+bonusID).attr('SendbackInProgress', 1);
		}
	}
	
	function updateSendbackState(selector)
	{
		$('img.sendBack', selector).addClass('disabledSendback').css('cursor', 'default').attr('src', 'gfx/act_indicator.gif').attr('title', 'Sending back is in progress');
	}

	
	
	
function compareTime(itemTime, olderThan)
{
	var now = new Date().getTime();
	var itemTime = new Date(itemTime*1000).getTime();
	
	var diff = now-itemTime;
	var secs = Math.floor(diff.valueOf()/1000);		
	return(secs > olderThan ? true : false);
}
	
</script>
</head>
<body>
	<div style="float: left; width: 20%;padding-top: 10px;">
		<div id="notices" style="margin: 0 10px; padding: 5px;height: 200px;" class="ui-widget ui-tabs ui-widget-content ui-corner-all">
			<div id="noticesScript" style="display:none"></div>
			<div id="noticesContent" style="height: 200px;overflow: auto; overflow-x hidden;">
			</div>
		</div>
	</div>
	
	<div style="float: left; width: 80%;padding-top: 10px;">
		<div id="gameSelector" style="margin: 0px 0px; display: block;text-align:center;"></div>
		
		<br />
	
		<h1 class="icon" style="background-image: url(gfx/32px-icon.png); margin-left: 0 10px;">Friendly Gaming Simplifier <span id="currentVersion"></span> <span id="currentTabName"></span> 
		
			<form action="https://www.paypal.com/cgi-bin/webscr" style="display: inline; float: right; margin-top: 4px; margin-right: 10px;" method="post" target="_blank">
				<input type="hidden" name="cmd" value="_s-xclick">
				<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----">
				<input style="width: 90px;background-color: transparent;border:0px;" type="image" src="gfx/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" />
			</form>
			
			<a name="fb_share" target="_blank" type="button" share_url="http://rzadki.eu/projects/fgs/?from=giftlist" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Frzadki.eu%2Fprojects%2Ffgs%2F%3Ffrom%3Dgiftlist&amp;src=sp"  style="float: right; margin-top: 8px;margin-right: 8px;text-decoration: none; "><span class="FBConnectButton FBConnectButton_Small" style="cursor:pointer;"><span class="FBConnectButton_Text">Share</span></span></a>
			
		
			<div id="fbLike" style="float: right; margin-top: 6px;">
				<iframe type="content" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FFGS%2F150480078326371&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>
			</div>
			
		</h1>
		<br style="clear: both" />
		
		<h2 style="text-align: center">
			<button style="font-size: 0.8em;" id="receiveBonusesAllGames">Receive bonuses from all games</button>
			<input type="checkbox" id="lockScreen" /><label for="lockScreen" style="font-size: 0.9em;">Screen is: UNLOCKED (click to lock)</label>
			<button style="font-size: 0.8em;" id="receiveGiftsAllGames">Receive gifts from all games</button>
			<br /><br />
			<button style="font-size: 0.8em;" id="stopReceivingQueue">Reset queue (<span id="queueItemsCount">0</span>)</button>
		</h2>
	</div>
		<br style="clear: both" />
		<br style="clear: both" />

		<div id="chat" style="padding: 20px" class="hide gameContent  ui-widget ui-tabs ui-widget-content ui-corner-all">
				<div align="left" id="chatUsers" class="chatContent right">
					<h2 style="text-align:center;border-bottom:1px dashed #000;padding-bottom:5px;">All users Chat</h2>
					<div class="shoutbox">
						<div class="shouts"></div>
					</div>
					
					<div class="onlinelist">
						<div class="onlineText"><strong>Users online:</strong></div>
						<div class="users"></div>
					</div>
					
					<div style="border-top: 1px dashed #000;padding-top: 10px;">
						<form method="post" action="javascript:void(0);" onsubmit="send(this)" id="publicChat" autocomplete="off">
							<img src="./gfx/act_indicator.gif" class="act_indicator" style="visibility: hidden; ">
							<strong>Message:</strong> <input type="text" tabindex="1" disabled="disabled" name="message" class="message" value="Chat is disabled, because your userdata was not retrieved yet">
								<!-- <input type="submit" class="sendChatBut button1" disabled="disabled" value="Send" name="submit" tabindex="6" accesskey="s">  -->
						</form>
					</div>
				</div>
				<br style="clear: both" />
		</div>
		
		<div id="options" class="hide gameContent">
			<ul>
				<li><a href="#gameOptionsTab">Game options</a></li>
				<li><a href="#optionTab-2">Settings</a></li>
				<li><a href="#optionTab-3">Import / Export</a></li>
			</ul>
			<div id="gameOptionsTab">
			
				
			</div>
			<div id="optionTab-2">
				<p>
					
					<div style="float: left;width: 45%;">
						<h1>Main work settings</h1>					
						
						<h4>Delete bonuses older than</h4>
							<select id="deleteOlderThan">
								<option value="0">Don't</option>
								<option value="1800">30 minutes</option>
								<option value="3600">1 hour</option>
								<option value="7200">2 hours</option>
								<option value="10800">3 hours</option>
								<option value="21600">6 hours</option>
								<option value="43200">12 hours</option>
								<option value="86400">1 day</option>
								<option value="172800">2 days</option>
								<option value="259200">3 days</option>
								<option value="604800">7 days</option>
								<option value="1209600">14 days</option>
								<option value="2592000">30 days</option>
							</select>
						
						<h4>Delete history older than</h4>
							<select id="deleteHistoryOlderThan">
								<option value="0">Don't</option>
								<option value="1800">30 minutes</option>
								<option value="3600">1 hour</option>
								<option value="7200">2 hours</option>
								<option value="10800">3 hours</option>
								<option value="21600">6 hours</option>
								<option value="43200">12 hours</option>
								<option value="86400">1 day</option>
								<option value="172800">2 days</option>
								<option value="259200">3 days</option>		
								<option value="604800">7 days</option>
								<option value="1209600">14 days</option>
								<option value="2592000">30 days</option>
							</select>
					

					
						
						<h4>How many bonuses to COLLECT at the same time (don't set it high unless you know what you're doing, change it only if you have very fast connection)</h4>
							<select id="collectXbonusesAtTheSameTime">
								<option value="1">1</option>
								<option value="2">2</option>
								<option value="3">3</option>
								<option value="4">4</option>
								<option value="5">5</option>
								<option value="10">10</option>
								<option value="15">15</option>
								<option value="25">25</option>
								<option value="30">30</option>
							</select>
						
						<h4>Show descriptions on FGS startup</h4>
							<select id="showDescriptionsOnStartup">
								<option value="0">No</option>
								<option value="1">Yes</option>
							</select>
						

						<h4>Bonuses check timeout</h4>
							<select id="checkBonusesTimeout">
								<option value="15">15 seconds</option>
								<option value="30">30 seconds</option>
								<option value="60">1 minute</option>
								<option value="120">2 minutes</option>
								<option value="180">3 minutes</option>
								<option value="300">5 minutes</option>
								<option value="600">10 minutes</option>
								<option value="900">15 minutes</option>
								<option value="1800">30 minutes</option>
								<option value="3600">60 minutes</option>
								<option value="10800">180 minutes</option>
							</select>
						
						<!---
						<h4>Gifts check timeout</h4>
							<select id="checkRequestsTimeout">
								<option value="30">30 seconds</option>
								<option value="60">1 minute</option>
								<option value="120">2 minutes</option>
								<option value="300">5 minutes</option>
								<option value="600">10 minutes</option>
							</select>
						-->
						
						<h4>Chat check timeout</h4>
							<select id="checkChatTimeout">
								<option value="15">15 seconds</option>
								<option value="30">30 seconds</option>
								<option value="60">1 minute</option>
								<option value="120">2 minutes</option>
							</select>
						
						<br /><br /><br /><br />
						<h4>Default Comments Messages</h4>
						<div id="defaultCommentsMessages"></div>
					</div>
					
					<div style="float: right;width: 45%;">
						<h1>Startup collecting settings (advanced)</h1>
						
						<h2 style="color: red">Read this before changing anything in this section:</h2>
						
						Changing this settings RECKLESSLY might cause your FGS to stop working (or increase startup loading process up to 30-60 minutes). This settings are only meant for advanced users (and with high speed connections). Keep in mind that FGS won't allow you to get at once more than 2500 bonuses (it's coded maximum and switching settings won't increae it).<br /><br />
						What I mean is: even if you set it to collect bonuses up to 1 day old, FGS will stop after 2500th bonus was found.<br /><br />
						FGS will also stop, if it finds bonus that is/was already on your list.<br /><br />
						
						<h3>When should FGS stop processing feeds:</h3>
						
							<select id="breakStartupLoadingOption">
								<option value="0">after certain amount of bonuses was found</option>
								<option value="1">after bonuses are older then specific time</option>
							</select>
						
							<select id="breakStartupLoadingCount" style="display: none">
								<option value="100">100 items</option>
								<option value="200">200 items</option>
								<option value="300">300 items</option>
								<option value="500">500 items</option>
								<option value="1000">1000 items</option>
								<option value="1500">1500 items</option>
								<option value="2500">2500 items</option>
							</select>
							
							<select id="breakStartupLoadingTime" style="display: none">
								<option value="1800">older than 30 minutes</option>
								<option value="3600">older than 1 hour</option>
								<option value="7200">older than 2 hours</option>
								<option value="10800">older than 3 hours</option>
								<option value="21600">older than 6 hours</option>
								<option value="43200">older than 12 hours</option>
								<option value="86400">older than 1 day</option>
							</select>
					
					</div>

					<br style="clear: both" />
				</p>
			</div>
			<div id="optionTab-3">
				<p>			
					<h3 class="settings">Import / export settings</h3>
					
					<textarea cols="40" rows="5" id="settingsTextarea"></textarea><br /><br />
					
					<button id="importSettings">Import</button> <button id="exportSettings">Export</button>	<br /><br /><br />
					
					
					<h4>How to import:</h4>
					- open the file with previously exported settings<br />
					- select whole text inside it<br />
					- paste text into the above box and press import button
					
					<br /><br />
					
					<h4>How to export:</h4>
					- press export button<br />
					- copy selected text to the new file
				</p>
			</div>
		</div>
			
		<div id="contact" style="padding: 20px" class="hide gameContent  ui-widget ui-tabs ui-widget-content ui-corner-all">
			<h2>Please donate, if you feel this extension deserves it:</h2><br />
			
					
			<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
				<input type="hidden" name="cmd" value="_s-xclick">
				<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----">
				<input style="width: 90px;background-color: transparent;border:0px;" type="image" src="gfx/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
			</form>
			
			<br /><br />
			
			<h2>If you need to contact me, use these links:</h2><br />
				<a href="http://facebook.com/fliesPL" target="_blank" title="Go to my Facebook profile"><img src="gfx/facebook.png" width="48" height="48" alt="Facebook"></a>
				<a href="http://fgs.rzadki.eu/#contact" target="_blank" title="Send me an e-mail"><img src="gfx/mail.png" width="48" height="48" alt="E-mail"></a>
				<a href="http://blog.fgs.rzadki.eu" target="_blank" title="Go to FGS Blog"><img src="gfx/blogger.png" width="48" height="48" alt="Blogger"></a>
			
			<br /><br /><br />
			
			<h2>If you encountered a problem, bug or want to file feature request, visit our message board:</h2><br />
				<a href="http://rzadki.eu/projects/fgs/board/" target="_blank" title="Go to FGS Board"><img src="gfx/forum.png" width="48" height="48" alt="Message Board"></a>
		</div>
	

	<div id="dialog-confirm" title="Delete?">
		<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><span class="text">Are you sure?</span></p>
	</div>
	
	<div id="dialog-error" title="Error">
		<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><span class="text"></span></p>
	</div>
	
	<div id="dialog-loading" title="Loading Gifts and Bonuses List">
		<h3 class="center"><img src="gfx/dl.gif"><br />FGS is loading... Please wait.</h3><br /><br />
		<span>(It may take a few minutes if you've got many bonuses in the database. If it takes very long - consider using Panic Button option)</span><br />
		<div id="progressbar"></div>
	</div>
	
	<div id="dialog-normal" title="Information window">
		
	</div>


	
	<ul id="myMenu" class="contextMenu">
		<li class="receive"><a href="#receive">Receive this bonus</a></li>
		<li class="receive"><a href="#receiveSimilar">Receive all "<span class="bonusName"></span> (<span class="bonusNameCount"></span>)"</a></li>
		<li class="delete separator"><a href="#delete">Delete this bonus</a></li>
		<li class="delete"><a href="#deleteSimilar">Delete all "<span class="bonusName"></span> (<span class="bonusNameCount"></span>)"</a></li>
		<li class="delete separator"><a href="#stopCollect">Don't collect this type of bonuses "<span class="bonusName"></span>"</a></li>
		<li class="copy separator"><a href="#copylink">Copy link</a></li>
		<li class="open separator"><a href="#openAndDelete">Open in new tab and delete</a></li>
		<li class="debug separator"><a href="#debug">Debug (for developer)</a></li>
	</ul>
	
	<ul id="myMenuManualBonuses" class="contextMenu">
		<li class="delete separator"><a href="#delete">Delete this bonus</a></li>
		<li class="delete"><a href="#deleteSimilar">Delete all "<span class="bonusName"></span> (<span class="bonusNameCount"></span>)"</a></li>
		<li class="delete separator"><a href="#stopCollect">Don't collect this type of bonuses "<span class="bonusName"></span>"</a></li>
		<li class="copy separator"><a href="#copylink">Copy link</a></li>
	</ul>
	
	<ul id="myMenuRequests" class="contextMenu">
		<li class="receive"><a href="#receive">Receive this gift</a></li>
		<li class="receive"><a href="#receiveSimilar">Receive all "<span class="bonusName"></span> (<span class="bonusNameCount"></span>)"</a></li>
		<li class="delete separator"><a href="#delete">Delete this gift</a></li>
		<li class="delete"><a href="#deleteSimilar">Delete all "<span class="bonusName"></span> (<span class="bonusNameCount"></span>)"</a></li>
		<li class="debug"><a href="#debug">Debug (for developer)</a></li>
	</ul>
	
	<ul id="myMenuDefaultGift" class="contextMenu">
		<li class="receive"><a href="#selectDefault">Select as default gift</a></li>
	</ul>
	
	<ul id="myMenuGameIcon" class="contextMenu">
		<li class="goToGame"><a href="#goToGame"><strong>Go to this game!</strong></a></li>
	</ul>
</body>
</html>